ClientLeaderboard: submit() method
@irtio/client 5.0BrowsersNodeThe submit() method of the ClientLeaderboard interface applies the board’s keep rule to this player’s entry in every period the board keeps, and resolves with what each period keeps.
Syntax
submit(score)
submit(score, options)
Parameters
score- A number: the score.
optionsOptional-
An object with any of these properties:
meta- An object whose values are strings, numbers and booleans: data to keep with the entry, at most 1 KB.
signal- An
AbortSignalthat aborts this call.
Return value
A Promise that resolves with an array of { period, score }, one for each period the board keeps, with the score the entry holds there now.
Exceptions
DataError- Rejects with this if the submit fails, such as with
E_FORBIDDENwhen the board doesn’t haveclientWrite: "own",E_UNKNOWNwhen the board isn’t declared or isn’t a leaderboard, orE_INVALIDformetaover 1 KB or not flat. An aborted call rejects withE_UNAVAILABLE, namedAbortError, orTimeoutErrorfor anAbortSignal.timeout(), with the signal’s reason as itscause.
Description
The board’s keep setting decides what each period’s entry holds: "best" keeps the better of the old and new score by the board’s order, "latest" the new one, and "sum" adds them.
The score is always this player’s. Without a token, the client gets a guest first if it has none.
Warning: Any player can submit any number from a client. For a board that matters, submit from room code with Leaderboard.submit(), which decides the score.
Examples
Submitting a daily puzzle’s moves
A daily puzzle with a board kept as "best" submits the player’s move count with the puzzle’s number, and tells them when it’s their best today.
// puzzle-moves.ts
import { dataClient } from "@irtio/client";
const board = dataClient().leaderboard("puzzle-moves");
export async function solved(moves: number, puzzle: number) {
const kept = await board.submit(moves, { meta: { puzzle } });
const today = kept.find((p) => p.period.startsWith("day"));
if (today?.score === moves) console.log(`a new best today: ${moves} moves`);
}
See also
ClientLeaderboard.top()Leaderboard.submit(), to submit from room code- Player data, collections and leaderboards
Runtime availability
| Browsers | Node | |
|---|---|---|
submit() | 5.0 | 5.0 |