question

astoresg avatar image
astoresg asked

getplayerstatistics and store in UI Text

I wish to get a particular value after a player logs in via Facebook. I am aware that GetPlayerStatistics() is the correct method to do so, but how do I go about storing this value? I am using Unity by the way and I wish to store it in a UI 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.

astoresg avatar image astoresg commented ·

I got away by doing something like this:

private void OnGetPlayerStatisticsSuccess(GetPlayerStatisticsResult result){

Debug.Log ("Success on getting Player's score.");

Dictionary<string, int> playerStatistics = new Dictionary<string, int>();
foreach (var each in result.Statistics) {
playerStatistics[each.StatisticName] = each.Value;
}

string s = playerStatistics ["Ranking"].ToString ();

}

but if you don't mind please explain why the previous error occured. I still don't quite understand the structure of GetPlayerStatisticsResult. :(

0 Likes 0 ·
brendan avatar image brendan astoresg commented ·

What error, specifically? There isn't one mentioned anywhere in this thread.

0 Likes 0 ·
astoresg avatar image astoresg commented ·

Hi,

@Brendan

I got the following errors while I tried implementing the methods:

The best overloaded method match for `System.Collections.Generic.List<PlayFab.ClientModels.StatisticValue>.this[int]' has some invalid arguments

Argument `#1' cannot convert `string' expression to type `int'

Script below:

private void GetPlayerStatistics(){
GetPlayerStatistics Request request=new GetPlayerStatisticsRequest();
PlayFabClientAPI.GetPlayerStatistics(request, OnGetPlayerStatisticsSuccess, PlayFabErrorCallBack);
}

private void OnGetPlayerStatisticsSuccess(GetPlayerStatisticsResult result){

Debug.Log("Success on getting Player's score.");
string s=result.Statistics["Ranking"].Value.ToString();

}

appreciate your help on this.

0 Likes 0 ·
brendan avatar image brendan astoresg commented ·

Ah, I see - the issue is that Statistics isn't a Dictionary, it's a List. So what you really want to do is a foreach on it, to find the Ranking statistic.

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

Actually, GetPlayerStatistics (and the write equivalent - UpdatePlayerStatistics) is for numeric values. Please see this tutorial on statistics and leaderboards for more on that topic: https://api.playfab.com/docs/tutorials/landing-players/player-statistics.

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

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.