Leaderboards #

Read more about the Leaderboards system in Hiro here.

Initializing the leaderboards system #

The leaderboards system system relies on the Nakama System and an ILogger, both must be passed in as dependencies via the constructor.

1
2
var leaderboardsSystem = new LeaderboardsSystem(logger, nakamaSystem;
systems.Add(leaderboardsSystem);

Getting leaderboard records #

You can get the user’s own cached record for a specific leaderboard.

1
var record = leaderboardsSystem.GetRecordAsync("<leaderboardId>");

You can also optionally specify a region ID to get the region specific score.

1
var usRecord = leaderboardsSystem.GetRecordAsync("<leaderboardId>", "US");

Getting leaderboard records for specific users #

You can get leaderboard records for a specific set of users, by providing either an array of user Ids, a list of friends or a Team (as defined in the TeamNakamaSystem).

For specific users:

1
var records = await leaderboardsSystem.GetRecordsAsync("<leaderboardId>", new[] { "<userId1>", "<userId2>" });

For friends:

1
2
var friendsList = await nakamaSystem.Client.ListFriendsAsync(nakamaSystem.Session);
var records = await leaderboardsSystem.GetRecordsAsync("<leaderboardId>", friendsList);

You can also specify the region to retrieve records for:

1
var records = await leaderboardsSystem.GetRecordsAsync("<leaderboardId>", new[] { "<userId1>", "<userId2>" }, 100, "US");

Getting the list of global leaderboard IDs #

You can get a list of global leaderboard IDs.

1
var leaderboardIds = leaderboardsSystem.GetLeaderboardIds();

Getting the list of regional for a leaderboard #

You can get a list of regions for a specified leaderboard.

1
var leaderboardRegions = leaderboardsSystem.GetLeaderboardRegions("<leaderboardId>");

Submitting a leaderboard score #

You can submit a leaderboard score for the user.

1
2
3
4
5
var score = 100;
var subscore = 10;
var metadata = "<metadataJson>";

var record = await leaderboardsSystem.WriteScoreAsync("<leaderboardId>", score, subscore, metadata);