Starting Replication
Getting Full Data
Section titled “Getting Full Data”When a player joins the game, you will need to send the current state of the world.
This can be done by calling server_replicator:get_full(player)
.
This will return two values:
- A
buffer
containing the data - A
variants
table contaning unserialized component values.
You will apply this in the client by calling client_replicator:apply_full(buffer, variants)
.
local replicator = require("@server/replicator")
-- remote function in the serverremotes_server.receive_full:set_callback(function(player) return replicator:get_full(player)end)
local replicator = require("@client/replicator")
-- remote function in the clientlocal buf, variants = remotes_client.receive_full:invoke_server()replicator:apply_full(buf, variants)
Activating Players
Section titled “Activating Players”Replecs will automatically ignore all players that have joined the game. This is to prevent players from getting updates when they haven’t received the full state of the world yet.
To activate a player to be replicated you will need to call server_replicator:mark_player_ready
.
You can check if a player has been marked as ready by calling server_replicator:is_player_ready
.
local replicator = require("@server/replicator")
-- remote function in the serverremotes_server.receive_full:set_callback(function(player: Player) replicator:mark_player_ready(player) return replicator:get_full(player)end)