Leaderboards
Declaring a board
Boards are declared in instaplay.json (up to 5 per game) and created on publish:
"leaderboards": [
{ "key": "main", "name": { "ru": "Лучший счёт", "en": "High score" },
"order": "desc", "format": "number",
"max": 1000000, "maxPerSecond": 500, "minIntervalMs": 1000, "minSessionMs": 5000 }
]
| Field | Value |
|---|---|
order |
desc — higher is better, asc — lower is better (time). Locked after publishing |
format |
number or time_ms (the portal shows m:ss.ms) |
max, min |
the allowed score range |
maxPerSecond |
"score per time": at most this per second of play |
minIntervalMs, minSessionMs |
submit frequency and minimal session age |
Submitting
const r = await InstaPlay.leaderboard.submit('main', 4200)
// { accepted: true, improved: ['day', 'week'], best: { day, week, all }, rank: { day, week, all } }
InstaPlay.leaderboard.submit(board, value) takes an integer. Only an improvement of the best result
in each period is stored. A rejection is a score_rejected error with details.reason
(not_integer, below_min, above_max, too_fast, too_frequent, session_too_young,
too_many_submits).
Reading
const page = await InstaPlay.leaderboard.get('main', { period: 'week', around: 'me', limit: 10 })
// { items: [{ rank, player: { id, nickname, avatar }, value, isMe }], me, periodStart, periodEnd }
InstaPlay.leaderboard.get(board, options?): period — day, week, all (default all);
around — top or me (a window around the player); limit 1…50.
Periods use Moscow time: a day starts at 00:00 MSK, a week — on Monday 00:00 MSK. The board is also shown on the game page (top 10 and a "You" row).