SetTimer: Difference between revisions
Jump to navigation
Jump to search
Automatyczna aktualizacja dokumentacji funkcji |
Complete Lua function catalog |
||
| Line 35: | Line 35: | ||
* Available in both client-side and server-side resource scripts. | * Available in both client-side and server-side resource scripts. | ||
[[Category:Lua Functions]] | |||
[[Category:Shared Functions]] | [[Category:Shared Functions]] | ||
[[Category:Timer Functions]] | [[Category:Timer Functions]] | ||
[[Category:Utility Functions]] | [[Category:Utility Functions]] | ||
Revision as of 09:55, 15 August 2026
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.