Cheat sheet
Every call you are likely to need on one page: the Godot addon first, then server Functions. Full details are in Godot addon, Function API and Client SDK.
Godot: connect
| Call |
What it does |
NetStack.connect_to_room(room_id, player_id) |
Join a room. Both are optional and fall back to Project Settings. |
NetStack.switch_room(room_id) |
Leave the current room and join another on the same connection. |
NetStack.leave_room() |
Leave the room and disconnect. |
NetStack.disconnect_from_server() |
Close the connection and stop reconnecting. |
NetStack.is_in_room(), get_state() |
Whether you are in a room, or the exact State. |
NetStack.get_local_player_id() |
Your player ID as the server knows it. |
NetStack.get_player_ids() |
Everyone in the room. |
Signals: joined(room), left, disconnected, connection_failed(reason), reconnecting(attempt, delay), player_joined(id), player_left(id), error_received(code, message).
Godot: call Functions
| Call |
What it does |
await NetStack.call_function(name, args) |
Run a server Function. Returns a NetStackResult and never throws. |
result.ok, result.value, result.get_value(key, default) |
Read a successful answer. |
result.error_code, result.error_message, result.has_error(code) |
Read a rejection. |
NetStack.on_function_result(name, callable) |
Run callable(result) whenever any call to name finishes, from anywhere in the game. |
NetStack.off_function_result(name, callable) |
Stop it. |
NetStack.function_completed(name, result) |
Signal version, for every Function. |
Godot: subscribe to a Function
Call a Function on a timer and hear about it only when its answer changes. Good for leaderboards, shop stock and match timers.
| Call |
What it does |
NetStack.subscribe_function(name, callable, args, interval_sec, only_on_change) |
Returns an id. callable(result) runs on the first answer and on every change. interval_sec = 0 means every multiplayer tick (at most 5 calls a second). |
NetStack.set_subscription_args(id, args) |
Send different arguments from the next call on. |
NetStack.unsubscribe_function(id), unsubscribe_all_functions() |
Stop. |
| NetStackFunctionSubscription node |
The same thing from the editor. Set function_name, args and interval_sec, connect updated(value) and failed(code, message). |
NetStack.subscribe_function("getLeaderboard", func(r): board.show(r.value), {"top": 10}, 2.0)
Godot: every multiplayer tick
| Call |
What it does |
NetStack.network_tick(tick, delta) |
Signal that fires once per server tick while in a room (30 a second by default), lined up with the server clock. |
NetStack.on_tick(callable), off_tick(callable) |
Same as connecting the signal. callable(tick, delta). |
NetStack.get_current_tick() |
The current tick number, or -1 outside a room. |
NetStack.get_tick_rate() |
Ticks per second for this project. |
NetStack.snapshot_received(tick, states) |
Signal for ticks that carried new player movement. |
NetStack.on_tick(func(_tick, _delta): NetStack.send_state({"pos": [position.x, position.y]}))
Godot: events and properties
| Call |
What it does |
NetStack.listen(event, callable), unlisten(event, callable) |
Run callable(data) when the server broadcasts event. |
NetStack.server_event(name, data) |
Signal for every event. |
NetStack.get_room_property(key, default) |
Read a room or global property. |
NetStack.get_player_property(key, player_id, default) |
Read a player property. Empty player_id means you. |
NetStack.get_room_properties(), get_player_properties(player_id) |
Everything at once. |
NetStack.watch_property(key, callable, scope, player_id) |
Run callable(value) now and on every change. scope is "room" or "player". Deleted sends null. |
NetStack.unwatch_property(key, callable) |
Stop. |
NetStack.property_changed(scope, player_id, key, value), property_deleted(...) |
Signals for every property. |
| NetStackPropertyBinding node |
Keep a Label, ProgressBar and so on in sync with one property. |
| NetStackEventListener node |
Emit received(data) for one event name. |
Godot: movement
| Call |
What it does |
NetStack.send_state(dict) |
Send your position, aim and so on. Latest value wins. |
NetStack.get_interpolated_state(player_id) |
Another player's state, smoothed. Use it to draw them. |
NetStack.get_player_state(player_id) |
Their newest raw state. |
NetStack.get_server_time_msec() |
The server clock, in milliseconds. |
Godot: ping and network checks
| Call |
What it does |
NetStack.get_ping() |
Latest round trip in milliseconds, or -1 before the first one. Updated about every 2 seconds. |
await NetStack.measure_ping() |
Measure right now. Returns -1 if not connected. |
NetStack.ping_updated(ping_msec) |
Signal on every new measurement. |
await NetStack.check_connectivity() |
Returns {status, message, netstack_reachable, internet_reachable}. status is ok, blocked, dns_blocked, offline or unknown. |
await NetStack.is_netstack_blocked() |
true when the internet works but NetStack does not, which usually means an ISP, school or office firewall. |
NetStack.connection_failed.connect(func(_reason):
var report = await NetStack.check_connectivity()
status_label.text = report.message)
Server Functions
Names below are JavaScript. In GDScript use erase instead of delete, state_at instead of stateAt, get(key, default), and fail(code, message) instead of throw.
| Call |
What it does |
ctx.player.id |
Who called. |
ctx.player.get(key) / set(key, value) / delete(key) / has(key) / keys() |
The caller's properties. get returns a copy, so set it back after changing it. |
ctx.players |
Everyone in the room, with the same methods. |
ctx.room.id, ctx.room.get / set / delete / has / keys |
Room properties. |
ctx.room.broadcast(event, data) |
Send an event to everyone in the room. |
ctx.room.state(playerId) |
A player's newest movement state. |
ctx.room.stateAt(playerId, time) |
Where they were at a recent server time. Use it for hit checks. |
ctx.global.get / set / delete / has / keys |
Properties shared by every room in the project. |
ctx.now |
Server time in milliseconds when the call started. |
ctx.log(...) |
A line in the dashboard's test run output. |
throw new NetStackError(code, message) |
Reject the call. Nothing it changed is kept. |
return value |
Sent back to the caller as result.value. Up to 32 KB. |
Errors you will see in the game
| Code |
Meaning |
NOT_CONNECTED |
You called a Function outside a room. |
CALL_TIMEOUT |
No answer within call_timeout seconds. |
DISCONNECTED |
The connection closed before the answer came. |
RATE_LIMITED |
More than 30 messages a second. Movement through send_state does not count. |
FUNCTION_ERROR |
The Function crashed. The dashboard's test run shows the line. |
| anything else |
A code your own Function chose. |
See Error codes for the full list.