Leaderboards

Ranked scores with automatic resets, archives of past periods and server-side anti-cheat.

On this page

Create a leaderboard#

Create leaderboards on the Leaderboards page of your project and use the slug in code.

SettingOptions
SlugLowercase identifier used in code, e.g. coins.
Sort orderDESC (highest first) or ASC (lowest first, e.g. race times).
Score modeBEST keeps each player's best score; LATEST always replaces it.
ResetNONE, DAILY, WEEKLY or MONTHLY.
Minimum / maximum scoreMinimum and maximum accepted score (optional).
Submit cooldownMinimum seconds between two submissions by one player (optional).

Submit a score#

The player name comes from the account, so a client cannot submit for someone else.

C#
var submit = await Majacloud.Leaderboards.SubmitScoreAsync("coins", 340);
if (submit.Ok && submit.Value.Accepted)
    Debug.Log("New rank #" + submit.Value.Entry.Rank);

Read rankings#

Top entries need no sign-in; the player's own rank and the entries around it need a signed-in player.

C#
var top = await Majacloud.Leaderboards.GetTopAsync("coins", limit: 10);
var me = await Majacloud.Leaderboards.GetMyRankAsync("coins");
var around = await Majacloud.Leaderboards.GetAroundMeAsync("coins", radius: 3);

if (me.Ok && me.Value.Entry != null) Debug.Log("You are #" + me.Value.Entry.Rank + " of " + me.Value.Total);

Resets and previous periods#

Daily, weekly (Monday) and monthly leaderboards reset at 00:00 UTC. The finished period is archived; read it with the previous period:

C#
var yesterday = await Majacloud.Leaderboards.GetTopAsync("coins", 10, 0, MajacloudLeaderboardPeriod.Previous);
How many past periods are kept, and how many entries a leaderboard returns, depends on the plan (see Limits).

Anti-cheat#

  • Scores outside the minimum or maximum are rejected with validation.
  • Submitting faster than the cooldown returns rate_limited.
  • Clients can only submit for the signed-in player.
  • For competitive games, let your server decide the score and submit it with the secret key.

Submit from your server#

With the secret key, send the player_id and the score. The player must exist.

JavaScript
// Node.js with secretKey: submit after your server validated the match
await admin.server.submitScore('coins', 'player_3f9c…', 980);

Search page titles, headings and text.

↑↓ to navigate ↵ to open Esc to close