Voidrush SDK – Data Module

The “Data Module” helps you synchronize your game state (saves, progression, snapshots) via structured messages. It relies on standardized message types that the backend understands and relays to all players in the room.

1) Updating the State

Two approaches:

  1. Direct Patch (state object update):
    client.updateGameState({ score: 42, level: 3 });
    Propagates game_state_update server-side → broadcasts to the room.
  2. Batch (list of structured updates):
    client.updateBatch([
      { entityId: "p1", state: { x: 100, y: 200 } },
      { entityId: "boss", state: { hp: 900 } }
    ]);
    The server validates the entries and broadcasts game.state_updates.

2) Generic Storage/Merge

You can also send a generic game.data message; the server relays it as is and attempts to save the payload as the current “game state,” which is useful for complete snapshots:

client.sendCustomMessage("game.data", { inventory, map, flags });

The consumer then emits type: "game.data" for all clients in the room and calls _save_game_state().

3) Retrieving the State (Sync)

To initialize a client or catch up mid-game:

// request current state
client.requestSync();
// you will receive "room.state" messages and the current game state
client.on("message", (m) => {
  if (m.type === "room.state") { /* lobby & presence */ }
  if (m.type === "game.state" || m.type === "game.data") { /* re-hydrate */ }
});

The server responds with the room state and returns the saved state.

4) Player Data (Profile/Ready/Team)

Some useful shortcuts:

5) Turn-Based: State & History

With TurnBasedGameClient:

tb.on("message", (m) => {
  if (m.type === "game.turn_move") { /* apply move */ }
  if (m.type === "game_turn_ended") { /* next player */ }
});
tb.sendMove({ from:"A2", to:"A3" });
tb.endTurn();

The server validates, applies to the game state, and broadcasts dedicated messages.

6) Best Practices