Skip to main content

The "wait" Function

Syntax#

wait(duration, [offset]);
ArgumentTypeDescription
durationrealSets the duration of time to wait, in seconds
[offset]realOptional: Sets the amount of time to offset the timer

Description#

Returns false for a specified interval, as a value of seconds, after which true will be returned for one frame. Repeats endlessly.

Note that this script's starting time is based on instance creation time, and will always return true at the same time for every instance of any object created in the same Step. Sometimes this synchronization is not desirable, in which case an optional offset time can also be supplied. Unlike the main time interval, the offset value can be either positive or negative. For example, to base starting time on global session time, use -game_get_time() (must be a variable declared in an event that is not run every Step).

Example#

//STEP EVENT
if (x != xprevious) or (y != yprevious) {
if (wait(1)) {
stamina--;
}
} else {
if (wait(2)) {
stamina++;
}
}
//LEFT MOUSE PRESSED EVENT
click_time = -game_get_time();
//LEFT MOUSE DOWN EVENT
if (wait(0.15, click_time)) {
instance_create_layer(x, y, layer, obj_bullet);
}