Trouble with timers.

Started by Cine Beast, Thu 25/08/2011 03:08:59

Previous topic - Next topic

Cine Beast

Yo, Cine Beast here. I'm nearly finished with my first game, and have encountered a problem that may or may not be a real problem (if it isn't, that's disheartening).

I have a room where four timers are in use. In the load of the room, timer 1 starts and lasts for 2 seconds. After that, in the Repeatedly Executing, timer 2 goes for 2 seconds, then 3, then 4. No problems.

However, at the timeout of 4, I want timer 1 to start (and have the cycle repeat endlessly). It does not.

I'm wondering if this is a standard thing - will a timer only work once. If it isn't, then I'd love some help. I'm inexperienced here, so if you need me to show my code or something, I'll need a hand with that, too.

Thanks in advance.

Baron

There is no limit to the number of times you can reuse or restart timers.  The source of your woes is probably the repeatedly_execute script that should start timer 1 after timer 4 expires.  Just like how you (presumably) started timers 2 through 4, it should look something like:

Code: ags

if (IsTimerExpired () ==4) {
     SetTimer (1, 80);
     //other code, etc.
     }

monkey0506

#2
IsTimerExpired takes the timer ID as its sole parameter and returns zero (false) or one (true).
So the code should look more like:

Code: ags
function repeatedly_execute()
{
  if (IsTimerExpired(4)) // or IsTimerExpired(4) == 1 or IsTimerExpired(4) == true, they're all the same
  {
    SetTimer(1, 80);
  }
}


@Cine Beast: Any time you have an issue like this, please make sure to post your code. This definitely sounds like a scripting error (as opposed to a bug in the engine), but we'd need to see the code to verify where exactly the problem is at.

Cine Beast

Okay, I rechecked my code, and found one of the stupidest, most easy-to-fix mistakes I've ever made.  :-[
I fixed the error, and now the timers work perfectly.

Thanks for the help, and sorry for the trouble.

SMF spam blocked by CleanTalk