Tasks and signals
task for running code alongside the game, and Signal for events.
The Explorer searches everything on this page, and the classes of the game too.
task
Runs functions as tasks: now, at the end of the frame, after a time, or again and again. A task can pause with task.wait, and the game goes on while it waits.
Type name: WaxTask.
task.spawn(f, ...)
Runs f(...) now, until it returns or first pauses.
task.spawn(f: function|thread, ...: any): thread| Parameter | Type |
|---|---|
f | function | thread |
... | any |
Returns thread
task.defer(f, ...)
Runs f(...) at the end of the current frame's step (or of the next one, when called outside a step).
task.defer(f: function|thread, ...: any): thread| Parameter | Type |
|---|---|
f | function | thread |
... | any |
Returns thread
task.delay(seconds, f, ...)
Runs f(...) after seconds, never earlier than the next frame.
task.delay(seconds: number, f: function|thread, ...: any): thread| Parameter | Type |
|---|---|
seconds | number |
f | function | thread |
... | any |
Returns thread
task.every(seconds, f, ...)
Runs f(...) again and again: the first time after seconds, then seconds after each run has ended. It never runs more than once a frame. An error in f is reported and the runs go on. After five errors in a row they stop. It stops when the mod unloads, and task.cancel stops it.
task.every(seconds: number, f: function, ...: any): thread| Parameter | Type |
|---|---|
seconds | number |
f | function |
... | any |
Returns thread
task.wait(seconds?)
Pauses the calling task for seconds (at least until the next frame) and returns the time it waited. It only works inside a task.
task.wait(seconds?: number): number| Parameter | Type |
|---|---|
seconds (optional) | number |
Returns number (waited)
task.cancel(thread)
Stops a task. It cannot be resumed afterwards.
task.cancel(thread: thread)| Parameter | Type |
|---|---|
thread | thread |
Returns nothing.
task.label(thread, label)
Names a task for error messages and the debugger.
task.label(thread: thread, label: string): thread| Parameter | Type |
|---|---|
thread | thread |
label | string |
Returns thread
Signal
Where a mod makes signals of its own: local Opened = Signal.new("Opened").
Type name: WaxSignalLibrary.
Signal.new(name?)
Creates a signal. The name labels its handlers in error reports.
Signal.new(name?: string): WaxSignal| Parameter | Type |
|---|---|
name (optional) | string |
Returns WaxSignal
WaxConnection
What Connect returns: one handler's link to a signal.
You get one from game.Players:ObserveCharacters, game.Creatures:Observe, game.Creatures:Highlight, signal:Connect, signal:Once, game.Frame:Connect, game.Frame:Once. Below, connection stands for one of these.
| Property | Type | Description |
|---|---|---|
Connected | boolean | False once the handler has been disconnected. |
connection:Disconnect()
Stops the handler from being called again.
connection:Disconnect()Returns nothing.
WaxSignal
An event that handlers connect to. F is the shape of a handler, as in WaxSignal<fun(name: string)>.
You get one from instance:GetAttributeChangedSignal, instance:GetPropertyChangedSignal, Signal.new. Below, signal stands for one of these.
signal:Connect(fn)
Calls fn on every Fire, newest connection first.
signal:Connect(fn: F): WaxConnection| Parameter | Type |
|---|---|
fn | F |
Returns WaxConnection
signal:Once(fn)
Like Connect, for the next Fire only.
signal:Once(fn: F): WaxConnection| Parameter | Type |
|---|---|
fn | F |
Returns WaxConnection
signal:Wait()
Pauses the calling task until the next Fire and returns what was fired.
signal:Wait(): ...anyReturns ...any
signal:Fire(...)
Calls every handler with these values. Each runs as a task and may pause.
signal:Fire(...: any)| Parameter | Type |
|---|---|
... | any |
Returns nothing.
signal:FireDirect(...)
Calls every handler directly, without a task. Handlers must not pause.
signal:FireDirect(...: any)| Parameter | Type |
|---|---|
... | any |
Returns nothing.
signal:DisconnectAll()
Disconnects every handler.
signal:DisconnectAll()Returns nothing.