Skip to main content

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

Last updated on October 24, 2024

Overview

The AccelByte Gaming Services (AGS) Leaderboard service empowers you to create a competitive atmosphere amongst players, by displaying the Leaderboard and providing information about player ranking.

This article walks you through how to use the SDK to retrieve a Leaderboard and a specific player's ranking.

Prerequisites

  • Access to the AGS Admin Portal.
  • Access to the AGS SDK for Unreal or Unity.
  • Access to the AGS Leaderboard API documentation for 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 succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetRankings fails
}));

Display a player's ranking

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

Get specific player's ranking

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

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


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