question

David Jones avatar image
David Jones asked

Showing player statistics to the client,Getting player statistics for client

How would I show player statistics on the top of the screen sort of how candy crush would show “lives” at the top on the menu screen. I tried to find documentation on the subject but no luck.

,

All I’m trying to do is post the some of the statistics on a player at the top of the screen like how candy crush would put “lives” etc on the top of screen so the user can see. I understand this will probably be a different process for a “currency” however how would I do this with a statistic? I tried to find some documentation or an example but I’ve run dry.

Leaderboards and Statistics
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.

David Jones avatar image David Jones commented ·

Did not mean to double post like that lol, the first one like disappeared and thought it didn’t post

0 Likes 0 ·

1 Answer

·
v-humcin avatar image
v-humcin answered

You can get the value for statistics using the GetPlayerStatistics API call (https://api.playfab.com/documentation/client/method/GetPlayerStatistics) How you would display the information gained from this will vary depending on the game engine or framework you are using so we can not provide a specific answer.

You can find a list of the supported platforms here (https://api.playfab.com/platforms) There are links to tutorials for some of platforms on that page to help you set up the API calls. I would then suggest finding another tutorial for your chosen platform on how to display text.

4 comments
10 |1200

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

David Jones avatar image David Jones commented ·

Sorry I didn’t realize I forgot to say I’m using unity C#, I have a text object I’m trying to set equal to a statistic. I called getuserstatistics im just trying to parse thru the response to pull out a certain stat value

0 Likes 0 ·
v-humcin avatar image v-humcin ♦ David Jones commented ·

To clarify are you using GetUserStatistics or GetPlayerStatistics? GetUserStatistics is deprecated and I would suggest updating and using GetPlayerStatistics.

I have a code snippet that I hope will make it easier to parse the statistics. In this example, I call GetPlayerStatistics with no arguments to return the full list of statistics so I have to sort through the list to find the desired value.

    void GetStatistics()
    {
        PlayFabClientAPI.GetPlayerStatistics(
            new GetPlayerStatisticsRequest(),
            OnGetStatistics,
            error => Debug.LogError(error.GenerateErrorReport())
        );


        
    }


    void OnGetStatistics(GetPlayerStatisticsResult result)
    {
        //Check each statistic in the list to see if it's the one you want
        foreach (var eachStat in result.Statistics)
        {
            if (eachStat.StatisticName.Equals("Score"))
          {
                score = eachStat.Value;
            }

        }
    }


This is only one method of finding the value in the list and you may want to approach it a different way or provide error checking in your actual code.

0 Likes 0 ·
v-humcin avatar image v-humcin ♦ v-humcin ♦ commented ·

Here is a second example to illustrate the the full path of how to access values from the result.

void GetStatistics()
    {
        //GetPlayerStatistics requires a list of strings if you want 
        //to specify which statistics you want
        List<string> statNames = new List<string> () { "Score" };
        
        PlayFabClientAPI.GetPlayerStatistics(
            new GetPlayerStatisticsRequest { StatisticNames = statNames },
            OnGetStatistics,
            error => Debug.LogError(error.GenerateErrorReport())
        );
    }


    void OnGetStatistics(GetPlayerStatisticsResult result)
    {
        Score = result.Statistics[0].Value;
    }

The important thing to note is that the result object contains the Statistics object which is a list of statistics and each statistic in that list has a StatisticName and Value.

You would want to have more error checking in your actual code, but hopefully this helps to understand how to parse the result.

0 Likes 0 ·
David Jones avatar image David Jones commented ·

Thank you that’s exactly what I needed

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.