WaitTimer -- wait until a timer has reached a certain time (V2.0)
WaitTimer(id, time[, reset])
This function halts the execution until the timer specified by id has reached the specified time. This time is specified in milliseconds. Before this function returns it will reset the specified timer so that you can easily use this function in a loop. You can change this behaviour by setting the optional argument reset to False. In that case, the timer will not be reset.

WaitTimer() is extremely useful if you want to limit the speed of certain loops. For instance, if you have a loop that moves a sprite from the left to the right boundary of the screen, you should add some kind of limitation so that it does not run faster than it should. This is very important. Even if the script runs at perfect speed without WaitTimer() you should not forget that there are faster machines than yours. Using WaitTimer() in your loops will make sure that your application runs on every system at the same speed.

See Script timing for details.

identifier of the timer to query
time in milliseconds that the timer must have
optional: specifies whether or not the timer shall be reset after WaitTimer() returns (defaults to True which means that the timer will be reset)
For k = 0 To 640
   DisplaySprite(1, k, 0)
   WaitTimer(1, 40)
The above code scrolls sprite 1 from left to right. After each call to DisplaySprite(), WaitTimer() is used to ensure that we wait at least 40 milliseconds until the next DisplaySprite(). Thus, this loop will not be executed more than 25 times a second because 40 * 25 = 1000.

Show TOC