create_comm_channel
Creates a communication channel for sending messages between actors.
Syntax
create_comm_channel() -> (number, ChannelReceiver)Returns
| Type | Description |
|---|---|
number | The one-based channel identifier |
ChannelReceiver | The receiver used to listen for messages |
Description
create_comm_channel creates a new communication channel that can be used to send and receive messages between actors and the main thread.
Channel Object
| Property/Method | Description |
|---|---|
Event | Signal used to receive messages |
connect(callback) | Connect a message callback |
Internal | BindableEvent used by the channel |
Example
local id, channel = create_comm_channel()
-- Listen for messages
channel.Event:Connect(function(message)
print("Received:", message)
end)
local actor = assert(getactors()[1], "No active actor state")
run_on_actor(actor, [[
local channelId = ...
local channel = get_comm_channel(channelId)
channel:Fire("Hello from actor!") -- get_comm_channel returns a BindableEvent
]], id)Bidirectional Communication
-- Main thread
local id, channel = create_comm_channel()
channel.Event:Connect(function(response)
print("Actor responded:", response)
end)
local actor = assert(getactors()[1], "No active actor state")
run_on_actor(actor, [[
local id = ...
local channel = get_comm_channel(id)
channel:Fire("Message received!")
]], id)Related Functions
get_comm_channel- Retrieve a channelrun_on_actor- Run code on an actor