ReferenceMulti-instance

apex.ipc.on

Calls a function for every message on a topic.

Syntax

apex.ipc.on(topic: string, callback: (peer: Peer, ...any) -> ()) -> Connection

Parameters

ParameterTypeDescription
topicstringA topic, or one of the Apex events "@join", "@leave" and "@shared".
callbackfunctionCalled with the sending Peer followed by the message's values.

Returns

TypeDescription
ConnectionHas Connected and Disconnect, like a Roblox connection.

Description

Each call runs as its own task on the game's script thread, so a callback may wait or yield without holding up other messages. Several callbacks can listen to one topic; all of them run. An error in one is reported in the output and does not affect the others.

The Apex events: "@join" (peer) when an instance enters a game, "@leave" (peer) when it leaves, closes or crashes, and "@shared" (peer, key, value) when another instance changes apex.ipc.shared.

Example

apex.ipc.on("goto", function(peer, position, options)
    print(peer.name, "asked for", position)
end)

apex.ipc.on("@leave", function(peer)
    warn(peer.name, "left")
end)

These are Game executor contracts. Check build requirements and session lifetimes before using them.