setTimer
Shared
Calls a function after an interval, once or repeatedly.
timer|false setTimer(function callback, float interval, any ... [, int repeats = 1])
Parameters
| Name | Type | Description |
|---|---|---|
| callback | function | The function to call. |
| interval | float | The interval in milliseconds, at least 1. |
| repeats | int | How many times to call it. 0 repeats forever.default 1 |
| ... | any | Arguments passed to the function on every call. |
Returns
The timer, or false if the interval is under 1 ms.
A resource's timers stop with it. If the server or the game stalls for several intervals, the timer is called once, not once per missed interval.
Example
local seconds = 10
setTimer(function()
seconds = seconds - 1
outputDebugString(seconds .. " seconds left")
end, 1000, seconds)Coming from MTAThe timer is a number, not an element, and belongs to the resource that created it: other resources cannot see it.