WaitTimer(id[, time, reset]) t = WaitTimer(table[, reset]) (V9.0)
id has been running
for the time specified in the time argument. This time must be specified
in milliseconds. If you omit the time argument or set it to -1, WaitTimer()
will wait until the timer has reached its elapse threshold set using SetTimerElapse()
or using StartTimer().
Before this function returns it will also 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.
Starting with Hollywood 9.0, there is an alternative way of using WaitTimer().
Instead of the identifier of a single timer, you can also pass a table
containing multiple timer identifiers. In that case, WaitTimer() will wait
until at least one of the timers from the list specified in the table argument
has elapsed. Once that happens, WaitTimer() will return a table to you.
That table will be a list containing the identifiers of all timers that have
elapsed. If the reset argument is True, which is also the default, all
elapsed timers will be reset by WaitTimer(). Note that the table you pass
to WaitTimer() can also be empty. In that case, WaitTimer() will simply
wait for a timer to elapse from all timers that are currently running.
WaitTimer() can be very useful to throttle the execution of loops so
that they don't consume all of the CPU. For instance, if you have a loop
that moves a sprite from the left to the right boundary of the display,
you should add some kind of throttle because it doesn't make sense to
update the screen more often than the monitor refreshes. 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 at
the same speed on every platform.
See Script timing for details.
WaitTimer() will return as soon as a timer from the list has
elapsed (see above); if you pass an empty table, all running timers will
be taken into accountWaitTimer() returns (defaults to True which means that
the timer will be reset)WaitTimer() (see above for details)StartTimer(1) For k = 0 To 640 DisplaySprite(1, k, 0) WaitTimer(1, 40) NextThe 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.