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.
Unity
Unreal
REST
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);
}
});
Input
You need to exchange the
TriggerGetScores
event for whatever event you want to use to trigger this flow. Replace the input variables with your leaderboard key, and how many items you want to get.Output
We recommend branching the completed events on the success flag in the response, and if you do this, you will probably want to add error handling in case the request fails as well as what (if any) continued actions you want on success. If you want to fetch more items on the score list, you'll want to save the pagination information for later use.
curl -X GET "https://api.lootlocker.io/game/leaderboards/1/list?count=10"
Unity
Unreal
REST
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);
}
});
Input
You need to exchange the
TriggerGetScores
event for whatever event you want to use to trigger this flow. Replace the input variables with your leaderboard key, how many items you want to get, and at what position in the list you want to start. If this is a continuation of a previous call to get scores (or GetScoreListInitial), you will want to use the cursor from the pagination data returned in the response from that call.Output
We recommend branching the completed events on the success flag in the response, and if you do this, you will probably want to add error handling in case the request fails as well as what (if any) continued actions you want on success. If you want to fetch more items on the score list, you'll want to save the pagination information for later use.
curl -X GET "https://api.lootlocker.io/game/leaderboards/1/list?count=10&after=10"
Unity Recommended Solution
Unreal
REST
Unity alternatives
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);
}
});
Input
You need to exchange the
TriggerGetScores
event for whatever event you want to use to trigger this flow. Replace the input variables with your leaderboard key and what member you want to fetch.Output
We recommend branching the completed events on the success flag in the response, and if you do this, you will probably want to add error handling in case the request fails as well as what (if any) continued actions you want on success.
curl -X GET "https://api.lootlocker.io/game/leaderboards/1/member/1"
The Unity SDK provides you with the ability to interact with the leaderboard using either leaderboardID or leaderboardKey, as well as having memberID as either a number or a string. Below, you can find these alternatives.
string leaderboardKey = "123";
int memberID = 50;
LootLockerSDKManager.GetMemberRank(leaderboardKey, memberID, (response) =>
{
if (response.statusCode == 200) {
Debug.Log("Successful");
} else {
Debug.Log("failed: " + response.Error);
}
});
int leaderboardID = 123;
int memberID = 50;
LootLockerSDKManager.GetMemberRank(leaderboardID, memberID, (response) =>
{
if (response.statusCode == 200) {
Debug.Log("Successful");
} else {
Debug.Log("failed: " + response.Error);
}
});
string leaderboardID = 123;
string memberID = "50";
LootLockerSDKManager.GetMemberRank(leaderboardID, memberID, (response) =>
{
if (response.statusCode == 200) {
Debug.Log("Successful");
} else {
Debug.Log("failed: " + response.Error);
}
});
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.
Unity
Unreal
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);
}
});
Input
You need to exchange the
TriggerGetScores
event for whatever event you want to use to trigger this flow. Replace the input variables with your leaderboard key and the member id of the member you want to fetch scores around. Also replace the variables in step 2. Use the same leaderboard key, and specify how many scores you want to show before and after the member in question.Output
We recommend branching the completed events on the success flag in the response, and if you do this, you will probably want to add error handling in case the request fails as well as what (if any) continued actions you want on success.
curl -X GET "https://api.lootlocker.io/game/leaderboards/1/member/1"
# player gets returned with rank 55
curl -X GET "https://api.lootlocker.io/game/leaderboards/1/list?count=10&after=49"
This can be used for doing things like friend leaderboards.
Unity
Unreal
REST
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);
}
});
Input
You need to exchange the
TriggerGetScores
event for whatever event you want to use to trigger this flow. Replace the input variables with your leaderboard key and a list of the member ids you want to fetch scores for.Output
We recommend branching the completed events on the success flag in the response, and if you do this, you will probably want to add error handling in case the request fails as well as what (if any) continued actions you want on success.
curl -X POST "https://api.lootlocker.io/game/leaderboards/1/members" -H "x-session-token: your_token_here" -H "Content-Type: application/json" -d "{\"members\": [\"1\", \"2\"]}"
Last modified 3mo ago