Page 1 of 1

Loop issues.

PostPosted: Fri Jul 01, 2011 12:56 pm
by Guardian69
Hi guys,

I have declared a global variable called m0nst3rAnimPos, and initiated it to 0 in the actors create event.

I have then put the following script in the actors draw event script.

if (m0nst3rAnimPos == 0)
{
m0nst3rAnimPos = 1;
playerOverlay.animpos = 0;
}
if (m0nst3rAnimPos == 1)
{
m0nst3rAnimPos = 0;
playerOverlay.animpos = 8;
}

Essentially, I am alternating a frame every loop to prototype an idle animation. However, it seems to get stuck on frame 8.

This seems like it should be really simple. Any ideas?

Re: Loop issues.

PostPosted: Fri Jul 01, 2011 1:02 pm
by Guardian69
I'm actually realised there is a better way and I am going to change this anyway, but would like to know the answer, just incase it is something to do with global scope???

Re: Loop issues.

PostPosted: Fri Jul 01, 2011 3:04 pm
by Kodo
We all started somewhere Guardian69, and we are all still learning :)

If your m0nst3rAnimPos variable is going to be used by lots of clones you will want it to be an Actor Variable and not global. Otherwise all the clones will be updating the same single global variable rather than just their own version of it..

Also, the code you have in the draw actor is run every frame, so the animpos for the respective clone is being set/changed some 30 times a second, probably not what you want. If you wanted to change it once a second and the game is running at 30 frames a second you can use your own counter to control the animpos update, something like:

Note that 'count ' is an Actor variable (int)
Code: Select all
if (count == 30)
{
  count = 0; // reset the counter

  if (m0nst3rAnimPos == 0)
  {
   m0nst3rAnimPos = 1;
   playerOverlay.animpos = 0;
  }
  if (m0nst3rAnimPos == 1)
  {
   m0nst3rAnimPos = 0;
   playerOverlay.animpos = 8;
  }
}

count++; // adds 1 to count