EntityStore: count property
Available since
@irtio/client 5.0BrowsersNodeThe count read-only property of the EntityStore interface is the number of entities the client holds.
Value
A whole number. It counts every entity the client holds: the shared state, its private state, a presence entry for each player in the room and the room’s entities in its view.
Description
A seated player in a room of four, with one entity of its own in view, has a count of 7: the shared state, its private state, four presence entries and its entity.
The room’s entities.count counts only the room’s entities, so the two differ. To count one kind, spread all() into an array.
Examples
Showing how much the client holds
A debug overlay shows the number of entities the client holds, next to the number of cards it sees.
// overlay.ts
import { connect, defineSchema, entity } from "@irtio/client";
const Card = entity("card", { suit: "u8", rank: "u8" });
const schema = defineSchema({ entities: [Card] });
const room = await connect("table-12", { schema });
room.addEventListener("update", () => {
console.log(`${room.entities.count} entities, ${[...room.entities.all(Card)].length} cards`);
});
See also
EntityStore.all()Entities.count, the room’s side
Runtime availability
| Browsers | Node | |
|---|---|---|
count | 5.0 | 5.0 |