NetStack

Properties

Properties are key-value state that NetStack stores and synchronizes for you.

Scopes

Player properties

Attached to one player. They are private by default: only that player receives them. Use them for inventories, currency and anything others should not see.

ctx.player.set("inventory", ["potion", "sword"]);
const gold = ctx.player.get("gold") ?? 0;

Room properties

Shared by everyone in a room and public to the room by default. Use them for scores, timers and lobby settings.

ctx.room.set("round", 3);

Global properties

Shared across every room in your project. Functions can read and write them, and you can edit them in the dashboard under Properties. Use them for counters, a message of the day or feature flags.

ctx.global.set("motd", "Double XP weekend");

Values and names

  • Values are JSON: strings, numbers, booleans, arrays, objects and null. A single value can be up to 64 KB.
  • Names use letters, numbers, underscores and hyphens, up to 64 characters, and must start with a letter or underscore. __proto__, constructor and prototype are reserved.
  • get returns a copy. Changing the returned object does nothing until you call set with it.
  • set(key, undefined) is an error. Use delete(key) to remove a property.

How clients see them

When a client joins, it receives a snapshot of room properties and the public properties of every player in the room. After that, changes arrive as propertyChange and propertyDelete events, and the SDK keeps a local copy you can read with getRoomProperties() and getPlayerProperties().

Persistence

Properties are stored per project and survive restarts. Player properties are keyed by player ID, so the same ID gets the same state the next time it joins.