Experimental

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

Report a problem
Module

@ember/signal

Script-made signals behave like host signals: firing queues the handlers for the next script slot.

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

Functions

signal.new<T...>() -> (types.Signal<T...>, (T...) -> ())
#

Returns a new signal and the function that fires it.

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

-- A signal of your own, for game events other parts of the script listen to. Annotating the
-- locals gives it its arguments: here a player and their points.
local scored: types.Signal<types.Player, number>, fireScored: (types.Player, number) -> () = signal.new()

scored:connect(function(player, points)
	player:send(`<green>+{points} points`)
end)

scored:connect(function(player, points)
	if points >= 10 then
		for _, other in players.all() do
			other:send(`<gold>{player.name} scored big!`)
		end
	end
end)

-- Firing queues every handler for the next script slot.
players.joined:connect(function(player)
	fireScored(player, 10)
end)