question

Kim Strasser avatar image
Kim Strasser asked

How can I return additional values for each player when I call client API GetLeaderboard?

For each player, I save the following values in one json Player ReadOnlyData key/value pair:

- Total levels played: xx

- Total achievements: xx

- Total points: xx

- Best rank in a leaderboard: xx

- playing time: xx

- Total player bans: xx

I know that I cannot get Player ReadOnlyData when I call PlayFabClientAPI.GetLeaderboard. But would it be possible to get these values with GetLeaderboard if I store them differently(not in ReadOnlyData)?

Where should I store the values so that I can get them for each player when I call GetLeaderboard?

Would it be possible to set "MaxResultsCount = 100" if I would return these values for each player with GetLeaderboard or would this be too much data that needs to be returned?

Right now, I only set "MaxResultsCount = 20" to return the 20 best players:

var result = await PlayFabClientAPI.GetLeaderboardAsync(new GetLeaderboardRequest()
{
    StatisticName = name,
    MaxResultsCount = 20,     
    ProfileConstraints = new PlayFab.ClientModels.PlayerProfileViewConstraints()
    {
        ShowDisplayName = true
    }

    foreach (var entry in result.Result.Leaderboard)
    {
        Console.WriteLine($"{entry.Position + 1} {entry.Profile.DisplayName} {entry.StatValue}");
    }

});
Leaderboards and Statistics
10 |1200

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

Seth Du avatar image
Seth Du answered

All the supported profile properties are listed in PlayerProfileViewConstraints section. It is feasible if you want to store somewhere else, however, please check the limits of each resource because usually it is not flexible like Player Data (internal/read-only).

In addition, though iteratively calling “get” APIs to retrieve data in Cloud Script will surly return an error, if you only have a small list (like 20 players) and you also remain the API call frequency with a specific range, it may work. Though you may work out the ‘frequency’ on your own.

8 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.

Kim Strasser avatar image Kim Strasser commented ·

I use ShowStatistics to get the players additional values but I have a problem with statistic versions.

What can I do if a certain statistic name has two different versions(last version and current version)?

How can I get the value of the current statistic version?

For example:

statisticvalue = stat.Value; gets executed two times because entry.Profile.Statistics has two entries for the statistic name "Total levels played" because it has the last and the current version of it.

How can I only get the value of the current version of "Total levels played"?

int statisticvalue;
string name = "Level 1-1";
var result = await PlayFabClientAPI.GetLeaderboardAsync(new GetLeaderboardRequest()
{
    StatisticName = name,
    MaxResultsCount = 20,     
    ProfileConstraints = new PlayFab.ClientModels.PlayerProfileViewConstraints()
    {
        ShowStatistics = true,
        ShowDisplayName = true,
        ShowAvatarUrl = true,
        ShowTags = true
    }
});

foreach (var entry in result.Result.Leaderboard)
{
    foreach (var stat in entry.Profile.Statistics)
    {
        if (stat.Name == "Total levels played")
            statisticvalue = stat.Value;
    }
}
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

Sorry but I don't understand why there are 2 versions of "Total levels played". In the common circumstance, Only current version of statistics will be returned. Would you share the complete response from Postman?

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Seth Du ♦ commented ·

Normally, I won't reset the leaderboard "Total levels played" and it will always have the version 0. But if I would reset it, then there are two statistics versions of "Total levels played". But I just need the value of the current version.

I want to get the value of the current version. In this case, that would be version 1 and its value 1. But the line statisticvalue = stat.Value; is executed two times, one time for version 0 and one time for version 1. Is it possible to execute it only once for the current version 1?

0 Likes 0 ·
Show more comments
Show more comments
giorgiotino avatar image
giorgiotino answered

I was about to ask the same exact question regarding the same exact issue. Since I cannot return "custom" data along with the GetLeaderboard response for each player, and since I need to know the MaxLevelPlayed and this is tracked by a Statistics, then I set ShowStatistics = true in the request but I was expecting to get only the current version for each stat, while instead I am getting more than one version (maybe current and previous?) for most of the Statistics.

I am not sure if I am getting the current and the previous only: in case, this would be acceptable - otherwise, since we have a weekly leaderboard, in a few months I would get a huge list of pointless old Statistics values. This would be terrible, but it's unclear if this is what happens.

@kim-strasser the way I have found to somehow figure out the right version almost automatically is to also request the PlayerStatistics in the Login API call. This call returns the current version for each statistic only, and I store it so that I know which number the current Version is. This way it's easy to only pick the current one from the list of Statistics returned by the GetLeaderboad call for each player.

Still, this seems weird and I wish I could control the granularity better: in a general way I don't care about older leaderboard versions in this scenario, at all.

By the way, the reset (in our case a manual one) happened 3-4 times, a few months ago. So I doubt it's a problem of caching and server data propagation...

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.