Before you start
- A board that already works with
submit()andtop(), from Add a leaderboard. - The SDK, or a current copy of
og-platform.js. A copy built before runs existed has nosubmitRun, so copy it again from@opengamehq/sdk/og-platform.
Declare the board
opengame.json
key, label, order, min and max. These fields are new:
Each column takes these fields:
A variant has a
key, a label and from 1 to 12 values, each with its own key and label. A value cannot be keyed all: the board with no filter is already “All”. Since a run may leave a variant out, each variant counts as its values plus one, and those counts multiplied together must stay at 48 or under. Der Koloss has 1 variant with 2 values, which makes 3 combinations.
opengame check checks each board with the same rules as the game API, and names the board and the field when one is invalid.
Best run or all runs
keep sets how many rows one player can have on the board.
beststores one run a player for each combination of tags: their best solo run, their best co-op run and their best untagged run. A read shows each player once, by their best run for the column it sorts by. Sorted by kills, a player’s highest-kill run is the row, even when a different run reached a later round.runsstores all runs, up torunsPerPlayera player for each combination of tags. Once a player has that many, a new run replaces their lowest-ranked one by score, and only when it is better. A read shows all stored runs, so the same player can appear several times.
runs, because its old site ranked 2,239 runs, not one per player, and a player who got to round 30 twice should see both.
Submit a run at game over
CallsubmitRun once, when the run ends:
js/leaderboard-client.js
og from @opengamehq/sdk instead. submit(value, meta) still works and is a run with no stats and no tags.
valueis the score: a finite number.statsmaps column keys to finite numbers. A stat the board does not declare is dropped and named inignored, such asstats.headshots, and the run still counts. All of them together fit in 512 bytes.tagsmaps variant keys to value keys. A key or value the board does not declare fails, and the run is not saved: withinvalid_runin local play, and withinvalid_requeston OpenGame. A run tagged with a mode the board does not have would appear only under “All”.
min and max the same way as the score: outside the range it is stored at the limit and the run is clamped, and past 10 times the limit the run is rejected. The run gets the lowest of those states, so one implausible stat takes the run off the board. saved.value.best is true when the run was kept on the board.
Read the board
top() takes a sort, a filter and an offset as well as a limit:
sortisscore(the default) or a column’s key. Each sorts in the column’sorder, so sorted bytime, the shortest run is first. Sorting by a column declaredsortable: falsefails: withinvalid_queryin local play, and withinvalid_requeston OpenGame.filtershows only runs with those tags. Leave it out for “All”, which is all runs, tagged or not.offsetskips rows, fortop()only, from 0 to 10,000. A page has at most 100 rows.
stats and tags next to score. A run that left a stat or a variant out has no key for it, so draw an empty cell. The page has total, the number of rows under that filter, and shape, which has the board’s scoreLabel, format, keep, columns and variants. Draw the column headings and the mode tabs from shape, not from a copy in the game, so a board edited in opengame.json looks the same in the game and on OpenGame. shape does not include the column bounds, because OpenGame uses them to keep implausible runs off the board and does not publish them.
The SDK checks that the game API applied the sort, filter and offset in the request. If it did not, the read fails with invalid_response, so your game does not show all runs under a Solo tab.
Career boards
A career board shows one row per player with totals across every match they played, such as matches, wins, win rate and average place. You don’t submit to it. Name the board whose runs feed it withfrom, and each accepted run on that board updates the player’s career row in
the same request.
Super Smash Royale feeds its career board from kills, a best board of KOs in a match with a
placement column and a map variant:
scoreAggis how each run’s score adds into the row’s score:sum,count,maxormin.- Each column has an
agg:countcounts runs.sum,max,minandavgreadof, which isscoreor a column of the source board.wherelimits any of them to runs that match, such asplacementequal to 1.ratiodivides two columns declared before it and multiplies byscale. Withrequires, the ratio is left out until that column reachesatLeast, so one lucky match does not top the win rate.
decimalsfixes how many decimals a column shows, so13.0%lines up with22.1%. An average or a ratio shows one unless you set it.- Variants must be the source board’s, with the same values. A run counts towards the player’s row for its own map and towards their All row.
- Only accepted runs count. A clamped or refused run on the source board adds nothing.
- A career board has no
minormax. Every run it counts was already held to the source board’s bounds. - A career board that holds rows keeps its
from, itsscoreAggand theaggof every column it has. You can rename it, change a column’s label, format or decimals, and add a column. To count a different way, declare a new board. - In local play a career board stays empty: the SDK checks its declaration and turns down runs sent to it, but only OpenGame adds runs up.
og.player.stats()reads the player’s row for all runs on every career board at once. Read stats back into your game has an XP and levels example.
Each number is the game’s claim
A stat is as forgeable as a score. Anybody with a browser console can sendkills: 99999. The bounds keep a wild number off the board, but a forged one inside them still appears. OpenGame labels the board as what the game reported, and does not use it to award prizes.
Test the board
Locally, the SDK reads./opengame.json with the same rules as opengame check. A local board has one entry, your best run by score, under either keep value. That entry has the run’s stats and tags. A filter shows it or hides it, sorting does not move it, and any offset skips it. Changing a board’s bounds, order, keep rule, columns or variants starts it fresh; changing a label does not.
top() results are cached for 30 seconds, so a new run can take that long to appear there.
Before you release:
- Submit a solo run and a co-op run in your private preview, with each stat filled in.
- Read
top({ filter: { mode: "solo" } })and confirm only the solo run is there, then read with no filter and confirm both are. - Sort by each column you declared sortable, and confirm
timeputs the shortest run first. - Submit a run with a stat the board does not declare, and confirm
ignorednames it. - On a
keep: "runs"board, submit more runs thanrunsPerPlayerand confirm the lowest-ranked run is replaced.
Fix a problem
invalid_run and invalid_query come from the checks the SDK runs before a request leaves the game, using the boards in your local opengame.json. On OpenGame the game API runs the same checks on the published board, and a run or a read it turns down is returned as invalid_request with reason http_400, without the field named. Test a new board in local play first.
Check value.ignored on a saved run. It names any stat the board does not have. If it names stats or tags themselves, the game API is older than this release and saved the score without them.
Where next
Add a leaderboard
The board fields, names, previews and error codes all boards share.
Read the scores API
The requests the SDK makes, for a game that calls the API itself.