Wax

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.

Open in the Explorer

task.spawn(f, ...)

Runs f(...) now, until it returns or first pauses.

task.spawn(f: function|thread, ...: any): thread
ParameterType
ffunction | thread
...any

Returns thread

Open in the Explorer

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
ParameterType
ffunction | thread
...any

Returns thread

Open in the Explorer

task.delay(seconds, f, ...)

Runs f(...) after seconds, never earlier than the next frame.

task.delay(seconds: number, f: function|thread, ...: any): thread
ParameterType
secondsnumber
ffunction | thread
...any

Returns thread

Open in the Explorer

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
ParameterType
secondsnumber
ffunction
...any

Returns thread

Open in the Explorer

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
ParameterType
seconds (optional)number

Returns number (waited)

Open in the Explorer

task.cancel(thread)

Stops a task. It cannot be resumed afterwards.

task.cancel(thread: thread)
ParameterType
threadthread

Returns nothing.

Open in the Explorer

task.label(thread, label)

Names a task for error messages and the debugger.

task.label(thread: thread, label: string): thread
ParameterType
threadthread
labelstring

Returns thread

Open in the Explorer

Signal

Where a mod makes signals of its own: local Opened = Signal.new("Opened").

Type name: WaxSignalLibrary.

Open in the Explorer

Signal.new(name?)

Creates a signal. The name labels its handlers in error reports.

Signal.new(name?: string): WaxSignal
ParameterType
name (optional)string

Returns WaxSignal

Open in the Explorer

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.

Open in the Explorer

PropertyTypeDescription
ConnectedbooleanFalse once the handler has been disconnected.

connection:Disconnect()

Stops the handler from being called again.

connection:Disconnect()

Returns nothing.

Open in the Explorer

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.

Open in the Explorer

signal:Connect(fn)

Calls fn on every Fire, newest connection first.

signal:Connect(fn: F): WaxConnection
ParameterType
fnF

Returns WaxConnection

Open in the Explorer

signal:Once(fn)

Like Connect, for the next Fire only.

signal:Once(fn: F): WaxConnection
ParameterType
fnF

Returns WaxConnection

Open in the Explorer

signal:Wait()

Pauses the calling task until the next Fire and returns what was fired.

signal:Wait(): ...any

Returns ...any

Open in the Explorer

signal:Fire(...)

Calls every handler with these values. Each runs as a task and may pause.

signal:Fire(...: any)
ParameterType
...any

Returns nothing.

Open in the Explorer

signal:FireDirect(...)

Calls every handler directly, without a task. Handlers must not pause.

signal:FireDirect(...: any)
ParameterType
...any

Returns nothing.

Open in the Explorer

signal:DisconnectAll()

Disconnects every handler.

signal:DisconnectAll()

Returns nothing.

Open in the Explorer

On this page