question

tarek-alhassan avatar image
tarek-alhassan asked

How to get a single Statistic for a player?

Hello,

I am currently trying to store 2 statistics to every new user. On the tutorial provided on this link:

https://api.playfab.com/docs/tutorials/landing-players/player-statistics

It clearly shows how is it possible to store multiple statistics. Sadly though, it only shows how to retrieve all player statistics at once using the following code:

PlayFabClientAPI.GetPlayerStatistics(newGetPlayerStatisticsRequest(),
result => Debug.Log("Strength retrieved"),
error => Debug.LogError(error.GenerateErrorReport())

);

My question is: How can I retrieve the value of a specific key from the statistics? or even better, How to retrieve them all and compare a specific key name and return its value (just like how you can get a specific key from PlayerData using this code: if (result.Data.ContainsKey("Coin")) )? I noticed that Statistics has: if (result.Statistics.Contains()) but it takes a type of item instead of a string.

Any help is very much appreciated.



Player Data
2 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.

tarek-alhassan avatar image tarek-alhassan commented ·

To clarify, I am using PlayfabServerAPI. Also, I seems like the information that I need is located on a different page:

publicvoidGetPlayerStatistics()

{

PlayFabServerAPI.GetPlayerStatistics( new GetPlayerStatisticsRequest()

{

PlayFabId = "_PlayFabId_",
StatisticNames = new List<string>() { "Coin" }

},

result => Debug.Log("Complete"),
error => Debug.Log(error.GenerateErrorReport())

);}

Although the above code seems like it would solve the issue, it always returns the following error:

NotImplementedException: The requested feature is not implemented.
PlayFab.PlayFabServerAPI.GetPlayerStatistics (PlayFab.ServerModels.GetPlayerStatisticsRequest getPlayerStatisticsRequest, System.Action`1 p1, System.Action`1 p2) (at Assets/PlayFabSdk/Server/PlayFabServerAPI.cs:157)
0 Likes 0 ·
tarek-alhassan avatar image tarek-alhassan commented ·

Another clarification: All I am trying to do here is print the value to a text field.

0 Likes 0 ·
pfnathan avatar image
pfnathan answered

Can you let us know what SDK you are on?

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.

tarek-alhassan avatar image tarek-alhassan commented ·

Hello @pfnathan and thank you for your reply. I am working Unity SDK.

0 Likes 0 ·
pfnathan avatar image
pfnathan answered

Also, can you reproduce this on Postman as well please, that API call worked fine in our testing, in both Client and Server APIs.

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.

tarek-alhassan avatar image tarek-alhassan commented ·

After you mentioned this, I tried to get the statistic using the Client API (although I stored it using the Server API), and it actually retrieved the statistic! Why do I still get that error when I use the Server API?

Another thing (although it might be a rooky question), How can I store the Statistic's value in a text filed?

0 Likes 0 ·
pfnathan avatar image
pfnathan answered

If you want to store and retrieve non-numeric values in the player account, you'll want to use one of the forms of player data available: https://api.playfab.com/docs/tutorials/landing-players/using-player-data

Also, please see this tutorial on statistics and leaderboards for more on the topic: https://api.playfab.com/docs/tutorials/landing-players/player-statistics

As for an error, Can you send, Title ID, PlayerID, the statistics that you are trying to fetch, and the input/output JSON of the equivalent call in postman.

10 |1200

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

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.