Timers library¶
Easy way to create and use timers. Timer’s resolution depends on server’s tick rate. So calculate min timer interval using 1000/tickrate.
Functions¶
create¶
Creates a new timer:
timer.create(name, delay, repeat, callback)
Arguments¶
stringname- name of a timer. Can be
nil. Name should be unique
numberdelay- timer delay in milliseconds
booleanrepeat- should timer repeat every
delayms or run only once
functioncallback- callback function that will fire on every tick
Returns¶
LuaTimertimer with methodsstart,pause,stop,destroy
get¶
Returns timer object by it’s name:
timer.get(name)
Arguments¶
stringname- name of a timer
Returns¶
LuaTimerornilif not found
setHighResolution¶
Warning
Use this on your own risk. This may cause exceptions and other weird stuff.
Sets all timers tick rate to 10ms:
timer.setHighResolution()
Examples¶
t = timer.create("timer1", 1000, true, function()
print("on tick")
timer.stop("timer1")
end)
t.start()