Getting started
Tasks and wait
Doing things over time without freezing the game.
A task is a function that can pause. wait(ms) inside a task pauses that task for at least ms milliseconds and lets the game carry on; the task continues on a later tick. The main file itself runs as a task, so it can wait too.
spawn(function()
while true do
local me = agents.local_player()
if me and me:health().percent < 50 then
combat.cast("Signet of Restoration")
end
wait(250)
end
end)spawn(fn, ...)integer
Starts a task that runs
fn(...), and returns its id. The task starts on the next tick.Pauses the current task for
ms milliseconds. Without an argument (or with 0) it waits for the next tick.Stops a task.
Rules
- Only tasks can
wait: the main file, and functions started withspawn. Callbacks such ason_tickcan't; spawn a task from them instead. waitinside a coroutine of your own pauses that coroutine, not the task.- Files loaded with
requirerun as part of whatever called it, so a module required from the main file can take several ticks to load, and canwait. - All of a plugin's tasks share one time budget each tick. A task that runs long simply pauses and continues on the next tick, and busy tasks take turns. See Limits and errors.