Skip to content

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.

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.

The client requests the current round state:

scripts/main.lua
Network:OnTableReceived(function(data)
if data.kind == "round_state" then
print("Round: " .. tostring(data.roundId))
end
end)
Network:SendTable({
kind = "get_round_state"
})

The server responds:

scripts/server.lua
Network:OnTableReceived(function(data)
if data.kind == "get_round_state" then
Network:SendTable({
kind = "round_state",
roundId = DefusalGame.RoundId
})
end
end)

The transport preserves:

  • string;
  • number;
  • boolean, including false;
  • 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
}
})
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.

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().

  • sending a Vector3, Agent, Texture, or function directly;
  • expecting a return value from SendTable();
  • omitting a field that identifies the message type;
  • trusting client-provided data in server game logic without validation.