Page 1 of 1

Basic timer framework

Posted: Tue Jul 29, 2008 11:37 am
by Jay
As it is not always easy (especially for beginners) to insert timers in your scripts in low level, i decided to make a simple 'timer framework'

Here it comes

Code: Select all

TIMERS
{
 0 [0]
 1 [0]
 2 [0]
 3 [0]
}

SetTimer[ (timer, time)
{
   TIMERS[timer]=self.time+StringCopy(time);
} ]

CheckTimer[ (timer)
{
   if(TIMERS[timer]=0)
   {
      return false;
   }
   if(self.time>TIMERS[timer])
   {
      TIMERS[timer]=0;
      return true;
   }
   return false;
} ]

Now you can use this with:

Code: Select all

SetTimer(0,2);
This will set the timer number 0 to 2 seconds.

and then when you want to check if the 2 seconds passed, you do:

Code: Select all

if(CheckTimer(0))
{
   //Do something
}
You can easily extend it by making the TIMERS array bigger.

Note that you have to reset all timers when you switch between low and high level (one of the reasons you should not switch too often, use low level whenever possible). The timers only work in low level.

Have fun!

EDIT: Added timer reset.

Re: Basic timer framework

Posted: Tue Jul 29, 2008 11:41 am
by Juutis
Another great little piece of script! Really useful to beginners. And even to more experienced guys too. :)

Re: Basic timer framework

Posted: Tue Jul 29, 2008 4:13 pm
by Kiji8989
what do you use it for? Like set a time limit on something? If so, I may use that! *gives anti computer cookie*

Re: Basic timer framework

Posted: Tue Jul 29, 2008 5:42 pm
by Jay
Yes, it can be used for various thinghs. For example, an enemy attacks, then you set a timer when it can attack again. Or a damage over time spell, that sets a timer each time it does damage.

You can also set a time limit, and when it's reached something happens.

Re: Basic timer framework

Posted: Fri Aug 01, 2008 10:21 am
by QuestOfDreams
This is pretty similar to the built-in script method AddTimerOrder(int Timer#, float Time, string Order); :wink: