SetTimer
Jump to navigation
Jump to search
setTimer
Schedules a Lua function to run after a delay, optionally more than once.
Syntax
int setTimer(function callback, int intervalMs, int timesToExecute, ...)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
callback |
function |
yes | The function to execute. |
intervalMs |
int |
yes | Delay between executions in milliseconds. The minimum is 10. |
timesToExecute |
int |
yes | Number of executions. Use 0 to repeat indefinitely. |
... |
any |
no | Optional values passed to the callback each time it runs. |
Returns
Returns a positive timer identifier on success, or 0 when the timer could not be created.
Examples
Print a message three times at one-second intervals:
local timer = setTimer(function(message)
print(message)
end, 1000, 3, "One second passed")
Notes
- Available in both client-side and server-side resource scripts.
- Expanded limits apply from update 0.1.3 BUILD81. Client limits: 8192 timers per resource, at most 256 selected callbacks per tick, oldest deadline first, and 32 callback arguments. The server has no corresponding fixed timer-count or callbacks-per-tick cap; memory and execution budgets still apply. See Scripting limits; earlier 0.1.3 binaries retain their old limits.