Network
Network connects the main.lua and server.lua sides of the same Reflex module. One side sends a Lua table with SendTable() and the other receives it through OnTableReceived().
Transport is not shown to the player automatically. The server normally makes a decision and sends compact state to the client; the client then updates UI, ImGui, audio, or a notification. SendTable() also does not wait for a response or confirm delivery through its return value.
How a message is processed
Section titled “How a message is processed”SendTable() serializes supported values from the table and transports the packet to the other half of the same Reflex module. On receipt, that runtime constructs a new Lua table and invokes the callback registered through OnTableReceived().
The sender does not call a server function directly and does not receive its result. If the protocol needs a response, the receiving side must send a separate message with its own kind and request identifier.
Quick example
Section titled “Quick example”The client requests the current round state:
Network:OnTableReceived(function(data) if data.kind == "round_state" then print("Round: " .. tostring(data.roundId)) endend)
Network:SendTable({ kind = "get_round_state"})The server responds:
Network:OnTableReceived(function(data) if data.kind == "get_round_state" then Network:SendTable({ kind = "round_state", roundId = DefusalGame.RoundId }) endend)Supported values
Section titled “Supported values”The transport preserves:
string;number;boolean, includingfalse;- nested tables;
- array-like tables such as
{ "first", "second" }.
nil, functions, and API objects such as Vector3 are not transported. A field containing one of these values is absent on the receiving side.
Network:SendTable({ position = Vector3.zero, -- omitted callback = function() end, -- omitted visible = false, -- transported options = { color = "blue", size = 2 }})Split a vector into numbers before sending it:
local position = Vector3.new(10, 20, 30)
Network:SendTable({ position = { x = position.x, y = position.y, z = position.z }})OnTableReceived
Section titled “OnTableReceived”Network:OnTableReceived(callback)Registers a callback for tables sent by the other side of the module.
| Argument | Type | Description |
|---|---|---|
callback |
function(data) |
Function receiving the reconstructed Lua table. |
The method returns nil.
SendTable
Section titled “SendTable”Network:SendTable(data)Sends a table to the other side of the Reflex module.
| Argument | Type | Description |
|---|---|---|
data |
table |
Message data. |
The method returns nil. Sending a table is not a request by itself. If a response is required, define message fields and handle the response through OnTableReceived().