apex.ipc.shared
Is a table every instance of this Apex install reads and writes.
Syntax
apex.ipc.shared: { [string]: any }
Description
Reading a key returns a copy of its value, or nil. Writing sets it for every instance; writing nil removes it. A write is visible to the writing script at once and reaches the other instances within a frame, where it raises "@shared" (peer, key, value). When two instances write the same key together, the later write wins everywhere. Iterate it with for k, v in apex.ipc.shared do; the loop sees a copy taken when it starts.
Keys are strings of 1 to 200 bytes. Values follow the rules of apex.ipc.send, up to 256 KiB each, and the table holds at most 4096 keys and 16 MiB. A write that would pass those limits raises an error.
Instances that join later see the whole table. It lasts while any instance of this install is running and is emptied when the last one closes.
Example
apex.ipc.shared.target = "Boss"
apex.ipc.shared.score = (apex.ipc.shared.score or 0) + 1
apex.ipc.on("@shared", function(peer, key, value)
print(peer.name, "set", key, "to", value)
end)
Notes
- Changing a table read from it changes only the copy: write the table back to share the change.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
