-
-
Notifications
You must be signed in to change notification settings - Fork 5
Timer
Anthony Headley edited this page Aug 17, 2023
·
5 revisions
Timer(function: onTick, number:interval, number: max_count[, function:cleanup][, userdata:context]) : nil
Runs a function 1 or more times based on the max_count and with a delay in seconds in the interval.
- The interval can be a int or float
- max_count MUST be a integer, 0 = forever
- the final userdata objects function is not known, if you pass it the Cleanup function may not run.
Name | Type | Description | Optional |
---|---|---|---|
onTick | function | a global function to call each tick | |
interval | number | the minimum time between calls can be an int or float | |
max_count | number | The number of times to call the function, 0 = forever. MUST BE AN INT If you pass a float (like 5.5) the onTick function might be called infinitely (not sure) | |
cleanup | function | Runs this function once the max_count has been hit | ✔ |
context | userdata | ⚠ Not sure what this should be, perhaps a display_handle? if you pass nil to this parameter then the cleanup will not be run! | ✔ |
nil
local function main()
Timer(onTick, 0.5, 5, onCleanup)
end
-- function must be global?
local function onTick()
Echo("onTick")
end
local function onCleanup()
Echo("Cleanup")
end
-- Output
-- onTick
-- <0.5 second delay>
-- onTick
-- <0.5 second delay>
-- onTick
-- <0.5 second delay>
-- onTick
-- <0.5 second delay>
-- onTick
-- Cleanup
return main