Combu  3.2.2
Unity API Documentation
Managing Leaderboards

In this section you will learn how to access the leaderboards data and report a score.

Loading Scores

To retrieve the scores list of a leaderboard you can call CombuManager.platform.LoadScores (by default loads the first page with 10 results), or you can instantiate a new Leaderboard object (created with CombuManager.platform.CreateLeaderboard), set timeScope, customTimescope and range and then call LoadScores:

// Load the scores of the leaderboard ID '123' from the page 2 with 10 results per page
CombuManager.platform.LoadScores(123, 2, 10, (IScore[] scores) => {
Debug.Log("Scores loaded: " + scores.Length);
});
// Load the scores of the leaderboard ID '123' from the page 1 with 10 results per page
ILeaderboard board = CombuManager.platform.CreateLeaderboard ();
board.id = "123";
board.timeScope = UnityEngine.SocialPlatforms.TimeScope.AllTime;
board.range = new UnityEngine.SocialPlatforms.Range(1, 10);
board.LoadScores((bool loaded) => {
// Now you can access board.scores and board.localUserScore
});

Reporting Scores

To report a new score of the local user you need to call CombuManager.platform.ReportScore, or you can call the method ReportScore on a Score instance:

// Report a score of 1000 to the leaderboard ID '123'
CombuManager.platform.ReportScore(1000, "123", (bool success) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed");
});
// Report a score of 1000 on a Score object,
// (previously loaded with LoadScores or a new with leaderboardID set)
myScore.value = 1000;
myScore.ReportScore( (bool success) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed");
});

Loading Leaderboards data

To load the leaderboards data like the title, description etc, you need to call Leaderboard.Load:

// Load the leaderboard ID '123'
Leaderboard.Load("123", (Leaderboard leaderboard, string error) => {
if (leaderboard != null)
Debug.Log("Success: " + leaderboard.title);
else
Debug.Log("Failed: " + error);
});

Loading the score of a user

To retrieve the best score of a user you need to call LoadScoreByUser on a Leaderboard instance:

// Load the best score of leaderboard ID '123' (or you can use the code) for the User object with 10 results per page (to be attendible 'page', the limit must be the same as used with LoadScores)
Leaderboard leaderboard = new Leaderboard { id = "123" };
leaderboard.LoadScoreByUser(CombuManager.localUser, eLeaderboardInterval.Total, 10, (Score score, int page, string error) => {
if (score != null)
Debug.Log("Success: rank #" + score.rank + " with value " + score.value + " at page " + page);
else
Debug.Log("Failed: " + error);
});
eLeaderboardInterval
Leaderboard interval.
Definition: CombuEnums.cs:53