multiplayer
Host, join and play a rollback match. Set this machine's input with set_input and read every slot's with rollback.input(slot); events are the…
Host, join and play a rollback match. Set this machine's input with set_input and read every slot's with rollback.input(slot); events are the multiplayer_event event: events::listen(node, "multiplayer_event"), heard as on_multiplayer_event, a map with a kind.
14 functions, 18 constants. Scripts reach it as multiplayer::.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
add_bot(str?) -> int? |
— | On a host, a slot its own script plays with set_input_for; answers the slot, or nil when the lobby is full. |
host(multiplayer::HostOptions?) -> multiplayer::Hosted |
— | Listen and take slot 0; answers { url, cert_hash, transport }, what a joiner needs. Options over [multiplayer]: transport, address, players, scene, depth, timeout_seconds, name, token. |
join(string, multiplayer::JoinOptions?) |
— | Dial a host at a ws:// or https:// url; connected or failed follows. Options: cert_hash for a self-signed host, name, token, timeout_seconds. |
leave() |
— | Say goodbye and go idle; a host leaving ends the match for everyone. |
local_player() -> int? |
— | This machine's own slot, or nil before it has one. |
players() -> [multiplayer::Player] |
— | Every slot as { slot, name, bot, local, status }, status as of the tick being simulated. |
role() -> str? |
— | ROLE_HOST or ROLE_CLIENT, or nil when idle. |
set_input(any) |
— | What this machine's player does on the next tick, until set again; ignored while a tick re-runs. |
set_input_for(int, any) |
— | The same for a bot slot this machine plays. |
settled_tick() -> int |
— | The tick before which nothing can be rolled back any more. |
start() -> bool |
— | On a host, start with whoever is in rather than waiting for players; false when there is no lobby to start. |
state() -> string |
— | STATE_IDLE, STATE_CONNECTING, STATE_LOBBY or STATE_PLAYING. |
stats(int) -> multiplayer::Stats? |
— | { rtt_ms, loss, bytes_in, bytes_out } for the link a slot is reached over; nil for this machine's own. An observer: never simulate from it. |
tick() -> int |
— | The match tick being simulated; what a match branches on instead of engine.tick. |
Constants
| name | value |
|---|---|
EVENT_CLOSED |
"closed" |
EVENT_CONNECTED |
"connected" |
EVENT_DESYNC |
"desync" |
EVENT_ERROR |
"error" |
EVENT_JOINED |
"joined" |
EVENT_LEFT |
"left" |
EVENT_STARTED |
"started" |
ROLE_CLIENT |
"client" |
ROLE_HOST |
"host" |
STATE_CONNECTING |
"connecting" |
STATE_IDLE |
"idle" |
STATE_LOBBY |
"lobby" |
STATE_PLAYING |
"playing" |
STATUS_ABSENT |
"absent" |
STATUS_PRESENT |
"present" |
TAG_LOCAL |
"local" |
TRANSPORT_WEBSOCKET |
"websocket" |
TRANSPORT_WEBTRANSPORT |
"webtransport" |