Volt

LuaStateProxy.Event

Generic event for communication between Lua states.

Syntax

state.Event: VoltSignal

Description

LuaStateProxy.Event is a VoltSignal property that allows communication between different Lua states. You can connect handlers to listen for events and fire events to send messages to other states.

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 = getgamestate()
local actorState = getluastate(someActor)

-- 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

On this page