ScriptSignal

Overview

Description

The ScriptSignal class is used to manage event-driven programming by emitting and connecting to signals. It allows developers to attach functions (callbacks) to signals, which will be executed when the signal is emitted.

Properties

Constructors

Methods

Connect

Connects a function (callback) to the signal. When the signal is emitted, the connected function will be called.

Parameters

function func

The callback function to connect to the signal. It will be triggered whenever the signal is emitted.

Return

ScriptConnection

Returns a `ScriptConnection` object that can be used to manage the connection to the signal.

Code Samples

local signal = ScriptSignal.new()

-- Example function
local function onSignalTriggered()
    print("Signal triggered!")
end

-- Connect the function to the signal
local connection = signal:Connect(onSignalTriggered)

-- Emit the signal
signal:Emit()

Once

Connects a function (callback) to the signal that will only be triggered once. Once the callback function is executed, the connection will automatically disconnect.

Parameters

function func

The callback function to connect to the signal. It will only be triggered the first time the signal is emitted.

Return

ScriptConnection

Returns a `ScriptConnection` object that can be used to manage the connection to the signal.

Code Samples

local signal = ScriptSignal.new()

-- Example function
local function onSignalTriggeredOnce()
    print("Signal triggered only once!")
end

-- Connect the function to the signal, only once
local connection = signal:Once(onSignalTriggeredOnce)

-- Emit the signal multiple times
signal:Emit() -- Triggers and disconnects the callback
signal:Emit() -- Does nothing as the callback is disconnected

Last updated