task¶
A global table of functions: task.<function>(…).
spawn¶
task.spawn: (f: ((...any) -> ...any) | thread, ...any) -> thread
Runs the function now, in a new task, until its first task.wait or its end; also takes a suspended coroutine. Returns the task's thread. An error in the task is logged, not raised here.
defer¶
task.defer: (f: ((...any) -> ...any) | thread, ...any) -> thread
Like spawn, but the task starts at the next drain: after the world's systems and the other tasks of this frame, or at the end of the frame. A task deferred while a drain runs starts at the next one.
delay¶
task.delay: (seconds: number, f: ((...any) -> ...any) | thread, ...any) -> thread
Like spawn, after that many seconds of game time (so it follows game.set_time_scale).
wait¶
task.wait: (seconds: number?) -> number
Pauses the running task for that many seconds of game time and returns how many really passed. nil or 0 waits for the next frame. It must run in a task (task.spawn, task.defer, task.delay or task.every), not at a module's top level or in a callback.
wait_real¶
task.wait_real: (seconds: number?) -> number
Like wait, on the real clock that game.set_time_scale does not change: a pause menu or a countdown while time is stopped.
every¶
task.every: (seconds: number, f: (...any) -> ...any, ...any) -> thread
Calls the function every that many seconds of game time, at most once per frame (the periods a long frame covers are skipped), until task.cancel or an error in it.
cancel¶
task.cancel: (task: thread) -> ()
Stops a task that is waiting or deferred, so that it never runs again. A thread that is over, or is not a task, is ignored. A task cannot cancel itself: return from it.
time¶
task.time: () -> number
The game seconds since the game started: the clock of wait, delay and every. It stops while the time scale is 0.
real_time¶
task.real_time: () -> number
The real seconds since the game started, whatever the time scale.