RoomClient: private property
@irtio/client 5.0BrowsersNodeThe private read-only property of the RoomClient interface is the player’s private state: the entity of the schema’s private kind that the room keeps for this player and sends to no one else.
Value
An OwnedEntity of the schema’s private kind, or undefined until ready resolves. On the client that connect() and ready resolve to, it’s typed as set.
Exceptions
TypeError- Thrown if a field that isn’t in the kind’s
writablelist is written.
Description
The player owns its private state, so the client can set the fields the private kind declares writable. Each write changes the field at once and is sent to the room as an owner write, at most once per room tick; the room applies it at the tick, and its own value overwrites it if the room corrects it. flush() sends the writes at once. The other fields are the room’s, and change only with state updates.
Private state is entity 1, so entities.onChange() with the schema’s private kind runs when its fields change. The room reads and writes it with room.private().
Examples
Choosing a loadout
The room keeps each player’s gold, and the player picks a loadout, the one field the room lets them write.
// loadout.ts
import { connect, defineSchema, entity } from "@irtio/client";
const Hero = entity("hero", { gold: "u32", loadout: "string" }, { writable: ["loadout"] });
const room = await connect("main", { schema: defineSchema({ private: Hero }) });
export function choose(loadout: "archer" | "knight") {
room.private.loadout = loadout;
console.log(`${loadout} chosen, ${room.private.gold} gold left`);
}
See also
RoomClient.stateRoom.private(), the room’s side- Ownership
Runtime availability
| Browsers | Node | |
|---|---|---|
private | 5.0 | 5.0 |