question

Darius Vu avatar image
Darius Vu asked

How to get my rank in the Leader Board?

Dear Team,

I am developing the leaderboard that will show my rank (for example rank 110) and top 10 highest score players.

As the question, how do I can get my rank in the Leader Board?

I tried to use GetLeaderboardAroundPlayer(), with my Playfab ID as below:

 public void GetLeaderBoardRank(string playfabID, Action<GetLeaderboardAroundPlayerResult> successCallback)
    {
        var request = new GetLeaderboardAroundPlayerRequest()
        {
            StatisticName = "Score_Data",
            PlayFabId = playfabID,  // This is my Playfab ID
        };

        PlayFabClientAPI.GetLeaderboardAroundPlayer(request, successCallback, errorCallbackReadLeaderBoard);
    }

But I see that the result is the list of Leaderboard, it is not only my rank (rank 110). So could you tell me how to get only my rank in the Leaderboard?

Thank you so much.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

In the common scenario, there should be 2 API calls.

  • GetLeaderboardAroundPlayer API to get the self’s rank via request:
{ "StatisticName": "xxxxx", "MaxResultsCount": 1}
  • GetLeaderboard API to get the top 10, via the request:
{
                
"StatisticName": "0",
"StartPosition": 0,
"MaxResultsCount": 10
}

PlayFabId is not a required property as by default, it will return self’s leaderboard directly.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Darius Vu avatar image Darius Vu commented ·

Done, it is working. And I put the code in here in order that other people can refer it. The result is the self’s rank.

public void GetLeaderBoardRank(string playfabID, Action<GetLeaderboardAroundPlayerResult> successCallback)
    {
        var request = new GetLeaderboardAroundPlayerRequest()
        {
            StatisticName = "Score_Data",
            MaxResultsCount = 1,
        };
        PlayFabClientAPI.GetLeaderboardAroundPlayer(request, successCallback, errorCallback);
    }

Thank you so much, SethDu.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.