LuaStateProxy.Event

Generic event for communication between Lua states.

Syntax

state.Event: VoltSignal

Description

LuaStateProxy.Event provides a way to communicate between Lua states, including across VM boundaries.

Example

local state = getluastate()

-- Listen for events
state.Event:Connect(function(message)
    print("Received:", message)
end)

-- Fire an event
state.Event:Fire("Hello from this state!")

Cross-State Communication

local gameState = assert(getgamestate(), "Game state is not available")
local actorState = assert(getactorstates()[1], "No active actor state")

-- Listen on game state
gameState.Event:Connect(function(message, senderId)
    print("Game state received:", message, "from state", senderId)
end)

-- Fire from actor state
actorState.Event:Fire("Hello from actor!", actorState.Id)

Broadcast to All States

local states = getactorstates()

-- Broadcast to all actor states
for _, state in ipairs(states) do
    if state.IsActorState then
        state.Event:Fire("Broadcast message")
    end
end