PlayerData: list() method

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The list() method of the PlayerData interface resolves with every key of the player’s data, with its value and version.

Syntax

list()

Parameters

None.

Return value

A Promise that resolves with an array of { key, value, version }, sorted by key.

Exceptions

The promise rejects with a DataError.

Description

list() is never cached: each call reads from the data service. A player has at most 256 keys, so it gives them all at once, with no paging.

Examples

Sending a player their unlocked items

Each unlock is its own key, such as unlock:rocket.

// unlocks.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onJoin(room, connection) {
    const keys = await room.playerData(connection.player).list();
    const unlocked = keys.filter((k) => k.key.startsWith("unlock:")).map((k) => k.key.slice("unlock:".length));
    room.send(connection, { type: "unlocked", items: unlocked });
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
list()0.10.10.10.1