Skip to main content

Display a player's ranking using the Leaderboard v1 (Legacy)

Last updated on May 13, 2024

Overview

The Leaderboard service empowers you to create a competitive atmosphere amongst players, by displaying the Leaderboard and providing information about player ranking.

Goals

In this section you will learn how to use the SDK to retrieve a Leaderboard, or retrieve just a specified player's ranking.

Prerequisites

  • Access to the AccelByte Admin Portal.
  • Access to the AccelByte SDK for Unreal or Unity.
  • Access to the AccelByte Leaderboard API documentation for further reference.

Display the Leaderboard Rankings

To display the Leaderboard rankings, you need to get the Leaderboard data. The data will be returned for the specified life cycle of the Leaderboard (daily, weekly, monthly, etc.). You can also specify a limit to the number of players that you want to retrieve data on (for example, top 10, or top 50). And you can specify an offset, so you can retrieve the next 10, next 50, and so on, if you wish to display the Leaderboard in pages.

You can use the following function to get the Leaderboard rankings:

Get Leaderboard rankings

FString LeaderboardCode = FString("SomeLeaderboardCode");
EAccelByteLeaderboardTimeFrame TimeFrame = EAccelByteLeaderboardTimeFrame::ALL_TIME;
int32 Offset = 0;
int32 Limit = 99;

FRegistry::Leaderboard.GetRankings(LeaderboardCode, TimeFrame, Offset, Limit, THandler<FAccelByteModelsLeaderboardRankingResult>::CreateLambda([](const FAccelByteModelsLeaderboardRankingResult& Result)
{
// Do something if GetRankings is successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetRankings has an error
}));

Display a player's ranking

You can display or highlight a specific player's rank.

You can get a specific player's ranking using the User ID, with the following function:

Get specific player's ranking

FString UserId = FString("SomeUserId");
FString LeaderboardCode = FString("SomeLeaderboardCode");


FRegistry::Leaderboard.GetUserRanking(UserId, LeaderboardCode, THandler<FAccelByteModelsUserRankingData>::CreateLambda([](const FAccelByteModelsUserRankingData& Result)
{
// Do something if GetUserRanking is successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRanking has an error
}));