Leaderboard: top() method
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe top() method of the Leaderboard interface resolves with a page of the best entries of a period, best first.
Syntax
top()
top(options)
Parameters
optionsOptional-
An object with any of these properties:
period- The period, as the
Leaderboardpage describes. Defaults to"all". limit- The most entries in the page, from 1 to 100. Defaults to 20.
after- The
nextof the page before, for the page after it.
Return value
A Promise that resolves with { entries, next }. next is null on the last page. Each entry is an object with these properties:
rank- Its rank, from 1.
player- The player’s ID.
score- The score the period keeps for the player.
meta- The
metathe last submit gave. updated- When the entry was last written, in wall-clock milliseconds.
Exceptions
The promise rejects with a DataError.
Description
top() is never cached, so call it on an event or every few seconds rather than every tick.
Examples
Showing today’s top ten in the lobby
// daily.ts
import { defineRoom } from "@irtio/room";
export default defineRoom({
async onJoin(room, connection) {
const { entries } = await room.leaderboard("points").top({ period: "day", limit: 10 });
room.send(connection, { type: "today", top: entries.map((e) => ({ rank: e.rank, player: e.player, score: e.score })) });
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
top() | 0.1 | 0.1 | 0.1 | 0.1 |