Timers and time
Run code later or on a beat. Game seconds: timers pause with the game.
mod.after(seconds, fn)
Section titled “mod.after(seconds, fn)”server + client
Calls fn() once, after seconds of game time. Server timers step about every 0.2 s; client timers run each frame, in a match only.
| Parameter | Type | |
|---|---|---|
seconds |
number |
0.05 to 86400. |
fn |
function |
No arguments. |
Returns a timer handle (a number)
Raises
seconds must be 0.05 to 86400callback must be a function
mod.after(10, function() mod.game.toast("TEN SECONDS IN")end)mod.every(seconds, fn)
Section titled “mod.every(seconds, fn)”server + client
Calls fn() every seconds of game time. A timer has no time limit; keep it short. One that errors 5 times stops.
| Parameter | Type | |
|---|---|---|
seconds |
number |
0.05 to 86400. |
fn |
function |
No arguments. |
Returns a timer handle (a number)
Raises
seconds must be 0.05 to 86400callback must be a function
local minutes = 0mod.every(60, function() minutes += 1end)mod.cancel(timer)
Section titled “mod.cancel(timer)”server + client
Stops a timer.
| Parameter | Type | |
|---|---|---|
timer |
number |
What mod.after or mod.every returned. |
local t = mod.every(1, function() end)mod.cancel(t)mod.time()
Section titled “mod.time()”server + client
Seconds on the game clock. Not the date, and not for timing code.
Returns number
mod.log("clock:", mod.time())