Retrieve Leaderboard Data

When wanting to retrieve and show leaderboard data we have a few scenarios:

  • Get the leaderboard from the top

  • Get a single entry on the leaderboards

  • Get a single entry score + surrounding entries score

  • Get specific scores for a list of members

Leaderboards can be interacted with either by id or by key. We recommend you always use the key. This is primarily because you can set the keys to be descriptive for you if you have multiple leaderboards; that way, you can tell them apart in your game. But another reason is that the keys are the same across environments, meaning you do not have to change them when the game goes live. That is not true for the ids.

Get the leaderboard from the top

Get the first items

string leaderboardKey = "ADescriptiveKey_ThatYouSetInTheConsole";
int count = 50;

LootLockerSDKManager.GetScoreList(leaderboardKey, count, 0, (response) =>
{
    if (response.statusCode == 200) {
        Debug.Log("Successful");
    } else {
        Debug.Log("failed: " + response.Error);
    }
});

Get the continuation of the leaderboard

string leaderboardKey = "ADescriptiveKey_ThatYouSetInTheConsole";
int count = 50;
int after = 50; // Set this to the cursor returned in the previous call

LootLockerSDKManager.GetScoreList(leaderboardKey, count, after, (response) =>
{
    if (response.statusCode == 200) {
        Debug.Log("Successful");
    } else {
        Debug.Log("failed: " + response.Error);
    }
});

Get a single entry on the leaderboards

string leaderboardKey = "ADescriptiveKey_ThatYouSetInTheConsole";
string memberID = "50";

LootLockerSDKManager.GetMemberRank(leaderboardKey, memberID, (response) =>
{
    if (response.statusCode == 200) {
        Debug.Log("Successful");
    } else {
        Debug.Log("failed: " + response.Error);
    }
});

Get a single entry score + surrounding entries score

Here we do 2 calls; first, we get the single entry for the member we're looking for, then we do another call to get the rest.

string leaderboardKey = "ADescriptiveKey_ThatYouSetInTheConsole";
string memberID = "50";

LootLockerSDKManager.GetMemberRank(leaderboardKey, memberID, (response) =>
{
    if (response.statusCode == 200)
    {
        int rank = response.rank;
        int count = 10;
        int after = rank < 6 ? 0 : rank - 5;

        LootLockerSDKManager.GetScoreList(leaderboardKey, count, after, (response) =>
        {
            if (response.statusCode == 200)
            {
                Debug.Log("Successful");
            }
            else
            {
                Debug.Log("failed: " + response.Error);
            }
        });
    }
    else
    {
        Debug.Log("failed: " + response.Error);
    }
});

Get specific scores for a list of members

This can be used for doing things like friend leaderboards.

string leaderboardKey = "ADescriptiveKey_ThatYouSetInTheConsole";
string[] memberIDs = new string[3]{"50", "105", "999"};

LootLockerSDKManager.GetByListOfMembers(leaderboardKey, memberIDs, (response) =>
{
    if (response.statusCode == 200) {
        Debug.Log("Successful");
    } else {
        Debug.Log("failed: " + response.Error);
    }
});

Last updated