Experimental

An early preview: docs, the API and the dashboard may change or break.

Report a problem

types.Signal

Handlers run in the script's slot of the tick after the event, and may yield.

Methods

signal:connect(handler: (T...) -> ()) -> types.Connection
#

Runs handler on every fire until the connection is disconnected.

local players = require("@ember/players")

-- `connect` runs the handler on every fire and returns a connection to stop it.
local greeting = players.joined:connect(function(player)
	player:send("<green>Welcome! Early birds get a bonus.")
end)

-- Stop greeting after the first minute.
task.delay(60, function()
	greeting:disconnect()
end)

-- `once` runs on the next fire only.
players.joined:once(function(player)
	player:send("<gold>You're first in!")
end)
signal:once(handler: (T...) -> ()) -> types.Connection
#

Runs handler on the next fire only.

signal:wait() -> T...
#

Yields the current task until the next fire and returns its arguments.

local players = require("@ember/players")
local ui = require("@ember/ui")
local world = require("@ember/world")

-- `wait` pauses a task until the signal next fires and returns what it fired with, so a scripted
-- sequence reads top to bottom. Like `task.wait`, it only works inside a task.
task.spawn(function()
	local plate = world.regions.single("pressure_plate")
	-- Nothing happens until someone steps on the plate.
	local first = plate.entered:wait()
	ui.title(players.all(), "<red>The gate opens!", { subtitle = `<gray>{first.name} stepped on the plate` })
	world.setBlock(vector.floor(world.markers.single("gate").position), "minecraft:air")
end)