wait (var time)
Pauses the current function, and resumes it after a frame cycle or after a time given in seconds.
Runs
other functions during the wait time.
Parameters:
time - either 1 to wait one frame, or a negative number between -0.01 .. -60 to wait the given number of seconds.
Speed:
Medium
Remarks:
- Wait returns from
the function (like return), stores its local
variables and the my and you pointers,
stores the function
state in an internal list (Scheduler List), and
returns to the calling function (if any). After the wait time,
the local variables and the my and you pointers are restored and
the function
is resumed with the line after the wait() call.
- While a function is waiting, all
other functions - including the calling function - continue to run in parallel, so all
global variables and all pointers except my and you can
possibly change during the wait time. !!
While the content of local variables is preserved, their addresses change after every wait() because the function runs every time in a different stack frame.
-
For determining if a function containing wait calls has really terminated, call proc_status() or use the wait_for() macro.
- wait(1) is often
used at the end of a while loop which is to be executed once per frame
cycle.
- The
minimum wait time is one frame
cycle, the maximum time is one minute
through wait(-60).
If you want to wait even
longer, use a loop.
-
Waiting functions are stored on the Scheduler List in the
order of their last wait() execution. This order can be modified by the proc_mode variable
(lite-C) resp. the proc_late function (C-Script).
The Scheduler List can be examined with the engine_gettaskinfo function.
Examples:
// let an entity light up for half a second, and then rotate it permanently
action rotator()
{
my.ambient = 100; // increase brightness
wait(-0.5); // wait 0.5 seconds
my.ambient = 0; // normal brightness
while (1) {
my.pan += 3*time_step; // rotate entity by 3 degrees per tick
wait(1); // wait one frame, then repeat
}
}
See also:
return, time_step, timer,
num_actions,
proc_status, wait_for, engine_gettaskinfo
► latest
version online