Basic timer framework
Posted: Tue Jul 29, 2008 11:37 am
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
Now you can use this with:
This will set the timer number 0 to 2 seconds.
and then when you want to check if the 2 seconds passed, you do:
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.
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;
} ]
Code: Select all
SetTimer(0,2);
and then when you want to check if the 2 seconds passed, you do:
Code: Select all
if(CheckTimer(0))
{
//Do something
}
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.