Leaderboard: around() method
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe around() method of the Leaderboard interface resolves with a player’s rank in a period and the entries either side of theirs, or undefined when the player has no entry there.
Syntax
around(player)
around(player, options)
Parameters
player- The player’s ID.
optionsOptional-
An object with any of these properties:
period- The period, as the
Leaderboardpage describes. Defaults to"all". count- How many entries to give on each side of the player’s, from 0 to 10. Defaults to 2.
Return value
A Promise that resolves with { rank, entries }, or undefined. rank is the player’s rank, and entries holds the player’s entry with up to count on each side, each as top() gives them.
Exceptions
The promise rejects with a DataError.
Description
around() is never cached.
Examples
Showing a player their rivals
// rivals.ts
import { defineRoom } from "@irtio/room";
export default defineRoom({
async onJoin(room, connection) {
const near = await room.leaderboard("points").around(connection.player, { period: "month", count: 3 });
if (near) room.send(connection, { type: "rivals", rank: near.rank, entries: near.entries });
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
around() | 0.1 | 0.1 | 0.1 | 0.1 |