question

Nicolas Dams avatar image
Nicolas Dams asked

Get the statisticName from GetLeaderboardAroundPlayerResult object?,How do get the statistic name by GetLeaderboardAroundPlayerResult?

Hello!

I use the Unity SDK and try to fetch a leaderboard with the GetLeaderboardAroundPlayerRequest. I start the request and create a new function for the result.

Now my "result function" contains the parameter result (type: GetLeaderboardAroundPlayerResult). It is possible to get the statistic name in the "result function"?

Background. I have a for loop which creates a few GetLeaderboardAroundPlayerRequest with different statistic names. Every request calls the same "success function".

Now i have the problem that i don't know which GetLeaderboardAroundPlayerResult belongs to which statistic name.

,

Hello!

I use the Unity SDK and try to fetch a leaderboard with the GetLeaderboardAroundPlayerRequest. I start the request and create a new function for the result.

Now my "result function" contains the parameter result (type: GetLeaderboardAroundPlayerResult). It is possible to get the statistic name in the "result function"?

Background. I have a for loop which creates a few GetLeaderboardAroundPlayerRequest with different statistic names. Every request calls the same "success function".

Now i have the problem that i don't know which GetLeaderboardAroundPlayerResult belongs to which statistic name.

10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

Hi Nicolas, in my opinion, it’s better for you to store the statistic name ahead for later use. I assume the problem you are facing here is that you don’t know how to access the statistics name in the result function so that you are wondering if you can access the statistic name in the GetLeaderboardAroundPlayerResult. Well, you can access statistic names if you set “ShowStatistics” to be true in the GetLeaderboardAroundPlayerRequest. However, I am pretty sure this is not what you expected, the result will return all the statistics for each player, which is more confusing for you to determine which statistic name is the right one. Therefore, it better to store the statistics ahead. I wrote this code to test storing statistic names ahead, it works fine, you can modify it to fit your demand. Anyway, here is the code:

    void GetLeaderBoardAroundPlayerWithStatistic(string statisticsName)
    {


        PlayFabClientAPI.GetLeaderboardAroundPlayer(
            new GetLeaderboardAroundPlayerRequest()
            {
                StatisticName = statisticsName,
                MaxResultsCount = 20

            },


            (GetLeaderboardAroundPlayerResult result) =>
            {
                // the parameter "statisticsName" passed to the method GetLeaderBoardAroundPlayerWithStatistic() is still within scope
                //you can still access it in the "result function"
                Debug.Log("Statistics name for the result: "+ statisticsName.ToString()); 

            },

            (PlayFabError error) =>
            {
                Debug.Log(error.ErrorDetails);
            }
            
            );
    }

The basic idea here is to wrap this whole GetLeaderBoardAroundPlayer logic within another method in order to make the statistic name still within scope for the “result function”.

10 |1200

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

Nicolas Dams avatar image
Nicolas Dams answered

Perfect. Thank you!

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.

Citrus Yan avatar image Citrus Yan commented ·

Glad it helped:)

0 Likes 0 ·

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.