Appearance
sdk.schedule
Timers on game.on("tick"). after / every are non-blocking. wait(ms) yields only when the caller is a coroutine.
lua
local M = require("sdk.schedule")now
function · now(): number
Host clock via game.log.now_ms, or 0. Same 0 convention as cavebot traces. after/every stamp due times with this.
Returns
| Type | Summary |
|---|---|
number | — |
pump
function · pump(now)
Run due jobs; periodic jobs reschedule, one-shots drop. Stable order: due time, then id. pcall so one callback cannot starve the rest.
after
function · after(delay_ms: number, callback: fun()): TimerId?, ErrorMessage?
One-shot callback after ms (non-blocking). ms is clamped to >= 0. Use wait() only from a coroutine.
Parameters
| Name | Type | Summary |
|---|---|---|
delay_ms | number | — |
callback | fun() | — |
Returns
| Type | Summary |
|---|---|
TimerId?, ErrorMessage? | — |
every
function · every(interval_ms: number, callback: fun()): TimerId?, ErrorMessage?
Repeating callback every ms (non-blocking). Period is at least 1 ms. cancel(id) to stop.
Parameters
| Name | Type | Summary |
|---|---|---|
interval_ms | number | — |
callback | fun() | — |
Returns
| Type | Summary |
|---|---|
TimerId?, ErrorMessage? | — |
cancel
function · cancel(id: TimerId): Result?, ErrorMessage?
Drop a job by id. Unknown id is nil, 'unknown'. Safe to call twice.
Parameters
| Name | Type | Summary |
|---|---|---|
id | TimerId | — |
Returns
| Type | Summary |
|---|---|
Result?, ErrorMessage? | — |
reset
function · reset()
Drop every job (session end / tests). Does not unhook tick; ensure() stays latched. In-flight wait() coroutines will hang if not resumed.
wait
function · wait(ms)
Suspend the current coroutine for at least ms without blocking the game thread. Calling this from a normal top-level script is an API error; use after there.
Parameters
| Name | Type | Summary |
|---|---|---|
ms | number | — |
Returns
| Type | Summary |
|---|---|
boolean|nil | ok |
string|nil | err |