Skip to content

Interface: Leaderboard

leaderboards.Leaderboard

Properties

name

Readonly name: string

The unique name of this leaderboard.

Defined in

leaderboards.ts:9

Methods

countRecords

countRecords(): Promise<number>

Get the number of records in this leaderboard.

Returns

Promise<number>

Defined in

leaderboards.ts:12


getRecords

getRecords(players): Promise<LeaderboardRecord[]>

Get the records for a given set of player IDs. Use account.getPlayerId to get the player ID of the local player.

const records = await leaderboard.getRecords([ playerId1, playerId2 ]);

Parameters

Name Type
players Iterable<string>

Returns

Promise<LeaderboardRecord[]>

Defined in

leaderboards.ts:34


listRecords

listRecords(opts?): Promise<LeaderboardRecord[]>

List the top 50 records in this leaderboard, ordered by score.

const records = await leaderboard.listRecords();
for (const record of records) {
    console.log(`Rank ${record.rank} is ${record.profileData?.name || "Anonymous"}`);
}

Parameters

Name Type
opts? ListRecordsOptions

Returns

Promise<LeaderboardRecord[]>

Defined in

leaderboards.ts:24


submitScore

submitScore(score, opts?): Promise<void>

Submit a record for the player.

A previously submitted record will only be replaced if the new record is "better" (score either higher or lower) than the previous submission.

Parameters

Name Type Description
score number The score number, which will be truncated to an integer. If you need decimals, consider multiplying the score by a fixed amount while submitting and dividing back when displaying the leaderboard.
opts? SubmitScoreOptions -

Returns

Promise<void>

Defined in

leaderboards.ts:46