timer_create - kemonologic/fuwafuwa Wiki

timer_create(time, [unit], [autoDestroy])

Returns: (map) A reference to the new timer.

Argument Type Name Desc
0 real/array time How long to set the timer for.
1 enum* unit The unit to use for the timer (default: time.ms)
2 bool* autoDestroy Whether to automatically destroy the timer (default: true)

Sets a timer and returns a reference to it which will be used for all other functions.


This is simply how long to set the timer for, and if unit isn't specified, milliseconds (time.ms) will be used. time is most often a single number; for example, the following will create a 500ms timer and assign it to the variable myTimer.

var _myTimer = timer_create(500);

time can also be an array. Using an array will create a timer sequence - the timer will be set to the first value of 500ms, and when it repeats or is restarted after the first 500ms timer is completed, the duration will be automatically set to 1000ms.

var _myTimer = timer_create([500,1000]);


Sets the timer unit. All functions on the timer will always use the unit specified here: for example, running timer_get_duration on a timer created with time set to 5 and unit set to time.s will return 5.

A note on terminology: "framelocked" means that a unit is based on game time (FPS) rather than real-world time. You can see a demonstration of this by setting the test project to various units and then dragging the window around. A framelocked unit will resume the timer at the same place it stopped because the game wasn't running, where a non-framelocked unit will skip ahead because time passed while the game was stopped.

Time unit Description
time.frames frames
time.ms milliseconds
time.s seconds
time.msframes milliseconds (framelocked)
time.sframes seconds (framelocked)


autoDestroy will set the timer to be automatically destroyed once the instance that created the timer is destroyed.

This is especially useful for cases in which you have a variable or large number of timers to set, and was added to maintain ease-of-use parity with alarms. As an alternative, you can manually destroy timers with timer_destroy if desired.