SetTimer
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.