question

Kamran Khan avatar image
Kamran Khan asked

How can i get all leaderboards.

I am storing playerscore, distance traveled, spriteindex, player name data using update PlayFabClientAPI.UpdatePlayerStatistics

public void SetStats()
{
    PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest
        {
            // request.Statistics is a list, so multiple StatisticUpdate objects can be defined if required.
            Statistics = new List<StatisticUpdate>
            {
                new StatisticUpdate {StatisticName = "PlayerLongestDistance", Value = playerLongestDistance},
                new StatisticUpdate {StatisticName = "KairiIndex", Value = _kairiIndex},
                new StatisticUpdate {StatisticName = "RaikiIndex", Value = _raikiIndex},
                new StatisticUpdate {StatisticName = "RavenIndex", Value = _ravenIndex},
            }
        },
        result => { Debug.Log("User statistics updated"); },
        error => { Debug.LogError(error.GenerateErrorReport()); });
}

I want to load all the data that is saved, I am using this function to get the leaderboard it is returning a single stat. How can i get all the stats stats that i have saved.

public void GetLeaderBoard()
{
    var requestLeaderBoard = new GetLeaderboardRequest
    {
        StartPosition = 0, StatisticName = "PlayerLongestDistance",
        MaxResultsCount = 20
    };

    PlayFabClientAPI.GetLeaderboard(requestLeaderBoard, OnGetLeaderBoard, OnErrorLeaderboard);
}
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.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

You can set the ProfileConstraints property as {"ShowStatistics": true} to get all statistics in the leaderboard entry. In Unity projects, the code would be something like this.

  private void OnLoginSuccess(LoginResult obj)
    {
        var request = new GetLeaderboardRequest { StatisticName = "Level", ProfileConstraints = new PlayerProfileViewConstraints { ShowStatistics = true } };
        PlayFabClientAPI.GetLeaderboard(request, OnSuccess, OnFailure);
    }


    private void OnSuccess(GetLeaderboardResult obj)
    {
        //Show the first player's all statistics.
        foreach (var item in obj.Leaderboard[0].Profile.Statistics)
        {
            Debug.Log(string.Format("Name: {0}, Version: {2} Value: {1}", item.Name, item.Value, item.Version));
        }

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