Skip to main content

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 reach every script's on_multiplayer_event as 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.

functionacts onwhat it does
add_bot(string?) -> anyOn a host, a slot its own script plays with set_input_for; answers the slot, or nil when the lobby is full.
host(any?) -> anyListen and take slot 0; answers { url, cert_hash, transport }, what a joiner needs. Options over [multiplayer]: transport, address, players, scene, depth, timeout, name, token.
join(string, any?) -> anyDial a host at a ws:// or https:// url; connected or failed follows. Options: cert_hash for a self-signed host, name, token, timeout.
leave() -> anySay goodbye and go idle; a host leaving ends the match for everyone.
local_player() -> anyThis machine's own slot, or nil before it has one.
players() -> anyEvery slot as { slot, name, bot, local, status }, status as of the tick being simulated.
role() -> anyROLE_HOST or ROLE_CLIENT, or nil when idle.
set_input(any) -> anyWhat this machine's player does on the next tick, until set again; ignored while a tick re-runs.
set_input_for(int, any) -> anyThe same for a bot slot this machine plays.
settled() -> anyThe tick before which nothing can be rolled back any more.
start() -> anyOn a host, start with whoever is in rather than waiting for players; false when there is no lobby to start.
state() -> anySTATE_IDLE, STATE_CONNECTING, STATE_LOBBY or STATE_PLAYING.
stats(int) -> any{ 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() -> anyThe match tick being simulated; what a match branches on instead of engine.tick.

Constants

namevalue
EVENT_CLOSEDclosed
EVENT_CONNECTEDconnected
EVENT_DESYNCdesync
EVENT_FAILEDfailed
EVENT_JOINEDjoined
EVENT_LEFTleft
EVENT_STARTEDstarted
ROLE_CLIENTclient
ROLE_HOSThost
STATE_CONNECTINGconnecting
STATE_IDLEidle
STATE_LOBBYlobby
STATE_PLAYINGplaying
STATUS_ABSENTabsent
STATUS_PRESENTpresent
TAG_LOCALlocal
TRANSPORT_WEBSOCKETwebsocket
TRANSPORT_WEBTRANSPORTwebtransport