Timer
Timers provide an easy way to execute functions after a specific time delay (timeout) or at recurring intervals.
Under the hood, the Timer API is entirely based on the Thread API. Therefore, timers share the exact same characteristics: they utilize the script VM's coroutines, do not block the game's main process, and run sequentially, meaning you don't have to worry about thread safety.
Quick Reference
| Name | Type | Description |
|---|---|---|
| SetInterval | Shared | Sets a recurring timer. |
| SetTimeout | Shared | Executes a function once after a specified delay. |
| Kill | Shared | Stops and removes a timer immediately. |
| IsAlive | Shared | Checks if a specific timer is currently registered and active. |
| GetRemaining | Shared | Returns the milliseconds remaining until the next execution. |
| GetRepeatsLeft | Shared | Returns the number of remaining executions for finite timers. |
| GetState | Shared | Returns the current state of the timer as a string. |
Shared Functions
SetInterval
Sets a recurring timer.
int timerId = Timer.SetInterval(int intervalMs, function func, int count, any ...)
SetTimeout
Executes a function once after a specified delay.
int timerId = Timer.SetTimeout(int delayMs, function func, any ...)
Kill
Stops and removes a timer immediately.
Timer.Kill(int timerId)
IsAlive
Checks if a specific timer is currently registered and active.
bool alive = Timer.IsAlive(int timerId)
GetRemaining
Returns the milliseconds remaining until the next execution.
int time = Timer.GetRemaining(int timerId)
GetRepeatsLeft
Returns the number of remaining executions for finite timers.
int repeats = Timer.GetRepeatsLeft(int timerId)
GetState
Returns the current state of the timer as a string ("running" or "dead").
string state = Timer.GetState(int timerId)