Skip to content

Use Leaderboards for Time Based Rankings

This how-to ranks entries by elapsed time by converting a time value into a sortable Leaderboard score.

Prerequisites

Submit Score

To rank entries by time, multiply the time value by a constant, such as 1000, before submitting it as the score. When you retrieve the Leaderboard, divide the score by the same constant to convert it back to a time value.

float time = 522.31f;
float timebasedScore = time * 1000f;
string leaderboardKey = "timebased_leaderboardKey";
LootLockerSDKManager.SubmitScore("", (int)timebasedScore, leaderboardKey, (response) =>
{
if (!response.success)
{
Debug.Log("Could not submit score!");
Debug.Log(response.errorData.ToString());
return;
}
});

Get Leaderboard Entries

string leaderboardKey = "timebased_leaderboardKey";
LootLockerSDKManager.GetScoreList(leaderboardKey, 10, (response) =>
{
if (!response.success)
{
Debug.Log("Could not get scores!");
Debug.Log(response.errorData.ToString());
return;
}
foreach(var entries in response.items)
{
float timebasedScore = entries.score / 1000;
Debug.Log($"Player {entries.player.name} had a time of {timebasedScore} ranking them {entries.rank} on the Leaderboard");
}
});

Conclusion

You've submitted and retrieved time-based rankings on a Leaderboard. Next, see Use Metadata to Store Additional Information to add more context to each entry.