Tasks and signals
task for running code alongside the game, and Signal for events.
task
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.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
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. 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, 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.