Simple counter code not working... help please.

Posted By: jaknine

Simple counter code not working... help please. - 07/12/08 01:10

Ok I am losing my mind here. It's been years since I last did a lot of work in 3DGS and I swear I'm not an idiot hahaha (I won third place in a 3DGS contest way back when so I at least know something lol).

Anyway, I have the following code:

Code:
action animate_this()
{
   while(1) 
   {
      my.skill1 += 2*time_step;
           
      if (my.skill1 > 100)  // if the animation section is finished playing...
      { 

      	my.skill1 -= 100; // start the animation over...
			
	thePicker +=1;
	show_Picker();

      	}

      ent_animate(me,"dance",my.skill1,ANM_CYCLE);

      wait(1);
   }
}

It's just a simple animation code that plays through a scene in an MDL file. It works fine, but...

The part where I have "thePicker +=1;" is throwing me for a loop. It's supposed to count up by one every time the animation reaches 100% and loops back. Then the "show_Picker" just prints the current value of thePicker to the screen.

The problem is, instead of it counting by 1 it's counting by 4. No matter what I change it refuses to count by one. Instead it goes: 4, 8, 12, 16, 18, and so on.

So...

How do I set a counter that will increase by 1 when a single cycle of an animation is finished playing?

Bonus points for telling me why this counter only counts by 4s.
Posted By: JazzDude

Re: Simple counter code not working... help please. - 07/12/08 01:55

Try thePicker = thePicker + 1;
Posted By: msl_manni

Re: Simple counter code not working... help please. - 07/12/08 04:01

show_Picker();

post the code related to show_Picker(). There must be some fault in there.
Posted By: jaknine

Re: Simple counter code not working... help please. - 07/12/08 05:14

Originally Posted By: JazzDude
Try thePicker = thePicker + 1;


Tried that and it does the same thing.
Posted By: jaknine

Re: Simple counter code not working... help please. - 07/12/08 05:18

Originally Posted By: msl_manni
show_Picker();

post the code related to show_Picker(). There must be some fault in there.

Here it is...

Code:
STRING theTempString = "#64";
STRING theNumString = "#4"; 

text showthis_txt
{
    layer = 15;
    pos_x = 200;
    pos_y = 5;
    font = _a4font;

}

function show_Picker()
{
    str_cpy(theTempString,"Picker = ");

    str_for_num(theNumString,thePicker);

    str_cat(theTempString, theNumString); 

    showthis_txt.string = theTempString;
    showthis_txt.visible = on;

}

I have theTempString set to a high number because I use it to test various strings on screen, not all of them so short.

I should also add that my MDL file has 200 frames of animation in it with 12 scenes named from "AAA" to "LLL" if that makes a difference.
Posted By: tD_Datura_v

Re: Simple counter code not working... help please. - 07/12/08 08:01


Quote:
I swear I'm not an idiot hahaha

That's a shame.
Certainly, manni and I might like a few peers as company in the thread.
wink
Code:
define _ani1, skill52;   // don't use skill 1, or share skills

var ani_nPicker = 0;

STRING s1[256];
STRING s2[256];
TEXT ani_t1 {
	strings = 1;
	pos_x = 0;
	pos_y = 0;
	layer = 15;
	font = _a4font;
}

function anif_showPicker() {
	str_cpy(ani_t1.string[0], "Picker: ");
	str_for_num(s2, ani_nPicker);
	str_cat(ani_t1.string[0], s2);
	ani_t1.visible = ON;
}
// no parenthesis for action
action animate_this {
	ani_nPicker = 0;
	while(me != NULL) {  // 
		my._ani1 += 2*time_step;  // well...
		//ani_nPicker += (ani_nPicker >= 99.998);
		ani_nPicker += (ani_nPicker >= 100);
		my._ani1 %= 100;
		ent_animate(me,"dance", my._ani1, ANM_CYCLE);
		anif_showPicker();
		wait(1);
	}
}
// model and / or this code could be a problem

Posted By: jaknine

Re: Simple counter code not working... help please. - 07/13/08 01:58

Originally Posted By: tD_Datura_v

Quote:
I swear I'm not an idiot hahaha

That's a shame.
Certainly, manni and I might like a few peers as company in the thread.
wink
Code:
...


Thanks for that code; even though the counter didn't work (heh) it got me thinking in different ways and I got done what I needed to get done in my program.
Posted By: TechMuc

Re: Simple counter code not working... help please. - 07/13/08 12:53

Probably you have 4 entities with the action animate_this.
As ThePicker is just a global variable it's counted by everyone of these entities
Posted By: jaknine

Re: Simple counter code not working... help please. - 07/15/08 06:43

Originally Posted By: TechMuc
Probably you have 4 entities with the action animate_this.
As ThePicker is just a global variable it's counted by everyone of these entities


Hah! I do have 4 entities controlled by it and that would indeed explain it. You get the bonus points. Thanks. smile
© 2024 lite-C Forums