Skip to main content

Timer

Timers provide an easy way to execute functions after a specific time delay (timeout) or at recurring intervals.

info

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

NameTypeDescription
SetIntervalSharedSets a recurring timer.
SetTimeoutSharedExecutes a function once after a specified delay.
KillSharedStops and removes a timer immediately.
IsAliveSharedChecks if a specific timer is currently registered and active.
GetRemainingSharedReturns the milliseconds remaining until the next execution.
GetRepeatsLeftSharedReturns the number of remaining executions for finite timers.
GetStateSharedReturns 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)