question

surlasha avatar image
surlasha asked

Player data based on leaderboard

public void SendLeaderboard(int winLossRatio) { var request = new UpdatePlayerStatisticsRequest { Statistics = new List<StatisticUpdate> { new StatisticUpdate { StatisticName = "WinLossRatio", Value = winLossRatio } } }; PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnLeaderboardUpdateError); } private void OnLeaderboardUpdate(UpdatePlayerStatisticsResult result) { GetLeaderboard(); } private void OnLeaderboardUpdateError(PlayFabError error) { Debug.LogError("On Leaderboard Update Error " + error.ErrorMessage); } public void GetLeaderboard() { var request = new GetLeaderboardRequest { StatisticName = "WinLossRatio", StartPosition = 0, MaxResultsCount = 10, }; PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardGet, OnLeaderboardGetError); } private void OnLeaderboardGet(GetLeaderboardResult result) { foreach (var item in result.Leaderboard) { var request = new GetUserDataRequest { PlayFabId = item.PlayFabId, Keys = new List<string> { "GamePlayed", "GameWon" }, }; PlayFabClientAPI.GetUserData(request, userDataResult => { }, userDataError => { }); } } private void OnLeaderboardGetError(PlayFabError error) { Debug.LogError("On Leaderboard Get Error " + error.ErrorMessage); }

here is my code, i was wondering if i am getting player data (title) correctly and if no how can I do it

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.

Xiao Zha avatar image
Xiao Zha answered

It is not recommended to use foreach to get user data based on leaderboard results because of api request limit. You can create another two statistics called “GamePlayed”and “GameWon”, then you can call GetLeaderBoard API to get “WinLossRatio” leaderboard and set the ShowStatistics option in ProfileConstraints property to true, then you can get the two statistics value in the API result.

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.

surlasha avatar image surlasha commented ·

Thank you kind stranger! It solved all my problems at once!

0 Likes 0 ·
drallcom3 avatar image
drallcom3 answered

You can store some data in the avatar URL. You get that one for "free" when grabbing leaderboard 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.