DataClient: leaderboard() method
Available since
@irtio/client 5.0BrowsersNodeThe leaderboard() method of the DataClient interface returns one of the project’s leaderboards: a collection declared with leaderboard settings in irt.config.ts.
Syntax
leaderboard(name)
Parameters
name- A string: the leaderboard’s name.
Return value
Exceptions
None. Its calls reject with a DataError; E_UNKNOWN means the board isn’t declared in the live build or isn’t a leaderboard.
Description
Reading a board needs its clientRead: true, and submitting a score its clientWrite: "own". The board’s periods, ranks and keep rule are as the Room API’s Leaderboard describes.
Examples
Showing the player’s rank
After a run, the client shows the player’s rank this week and the two players either side.
// my-rank.ts
import { dataClient } from "@irtio/client";
const laps = dataClient().leaderboard("laps");
export async function showRank() {
const near = await laps.around({ period: "week" });
if (!near) console.log("no lap this week yet");
else for (const e of near.entries) console.log(`${e.rank}. ${e.player} ${e.score} ms`);
}
See also
ClientLeaderboardRoomClient.leaderboard(), the same from a connected client- Player data, collections and leaderboards
Runtime availability
| Browsers | Node | |
|---|---|---|
leaderboard() | 5.0 | 5.0 |