Basic timer framework

Topics regarding Scripting with Reality Factory
Post Reply
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Basic timer framework

Post 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.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Basic timer framework

Post by Juutis »

Another great little piece of script! Really useful to beginners. And even to more experienced guys too. :)
Pain is only psychological.
User avatar
Kiji8989
Posts: 209
Joined: Tue Jul 22, 2008 11:39 pm

Re: Basic timer framework

Post 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*
(\_/)
(O.o) copy bunny into your signature to
( >< )help him achieve world domination
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Basic timer framework

Post 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.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Re: Basic timer framework

Post by QuestOfDreams »

This is pretty similar to the built-in script method AddTimerOrder(int Timer#, float Time, string Order); :wink:
Post Reply