Skip to main content

The "timer" Function


timer(id, [duration]);
idstringSets a unique timer ID, as a string
[duration]realOptional: Sets the duration of time to countdown, in seconds (use none to create timer only)


Sets and/or counts down a timer and returns false until the time has expired, after which it will return true. (To return the actual time value, see timer_get.)

The timer ID should be a unique string value. Timers and their IDs are local to the running instance, so multiple timers can use the same ID in different instances. However, the same ID cannot be reused within a single instance. Otherwise, there is no limit on the quantity of timers that can exist at once.

Timer duration is measured in seconds. This value is automatically adapted to framerate and delta time.


See the included interactive demo for a visual example of this function!


if (timer("t_alarm", 3)) {
//Action after 3 seconds