question

chintanshroff avatar image
chintanshroff asked

getLeaderboard api call,GetLeaderboard Call

Hi I am really struggling to see the default leaderboard UI in my game.

I couldnt quiet follow the documentation, here is what I did

1. I got the player to login with Facebook and inturn with Playfab, which works great

2. Then I am calling the following method every time the game ends to check if current score > Highscore -> UpdatePlayerStat (Which in turn updates the Leaderboard I hope)

 publicvoidSetStats()
{//Unity/C#
varrequest=newUpdatePlayerStatisticsRequest
{
Statistics =newList<StatisticUpdate>
{
newStatisticUpdate{ StatisticName ="TopScores", Value =GameManager.instance.HighScore},
//request.Statisticsisalist,somultipleStatisticUpdateobjscanbedefinedifrequired.
}
};
PlayFabClientAPI.UpdatePlayerStatistics(request,
result=>
{
Debug.Log("TopScoresset");
},
error=>
{
Debug.LogError(error.ErrorMessage);
});
}

3. Then I added a script to a Leaderboard button in my game to show the leaderboard with the follwing script. I burrowed this code from the unicorn game and tbh I dont understand it at all

public void ShowLeaderboard_PlayFab()

 {
 PlayFabClientAPI.GetLeaderboard(new GetLeaderboardRequest{ StatisticName = "Top Scores", StartPosition = 0, MaxResultsCount = 10 }, (GetLeaderboardResult r) =>

 {

 var leaderboard = r.Leaderboard;

 }, null);

 }

would be great if you could please help out here.

,

Hi I am really struggling to see the default leaderboard UI in my game.

I couldnt quiet follow the documentation, here is what I did

1. I got the player to login with Facebook and inturn with Playfab, which works great

2. Then I am calling the following method every time the game ends to check if current score > Highscore -> UpdatePlayerStat (Which in turn updates the Leaderboard I hope)

 publicvoidSetStats()
{//Unity/C#
varrequest=newUpdatePlayerStatisticsRequest
{
Statistics =newList<StatisticUpdate>
{
newStatisticUpdate{ StatisticName ="TopScores", Value =GameManager.instance.HighScore},
//request.Statisticsisalist,somultipleStatisticUpdateobjscanbedefinedifrequired.
}
};
PlayFabClientAPI.UpdatePlayerStatistics(request,
result=>
{
Debug.Log("TopScoresset");
},
error=>
{
Debug.LogError(error.ErrorMessage);
});
}

3. Then I added a script to a Leaderboard button in my game to show the leaderboard with the follwing script. I burrowed this code from the unicorn game and tbh I dont understand it at all

public void ShowLeaderboard_PlayFab()

    {
        PlayFabClientAPI.GetLeaderboard(new GetLeaderboardRequest{ StatisticName = "Top Scores", StartPosition = 0, MaxResultsCount = 10 }, (GetLeaderboardResult r) =>

            {

                var leaderboard = r.Leaderboard;

            }, null);

    }

would be great if you could please help out here.

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

·
brendan avatar image
brendan answered

Can you help to clarify what, specifically, you're having trouble with? Are the results coming back from the call to get the leaderboard entries not what you expect? If not, what are you seeing and what were you expecting?

For the UpdatePlayerStatistics call, yes, if you have set your leaderboard to "Max" aggregation, it will only update the player's score with the one you pass in if it's greater than the player's old score. If you haven't changed the aggregation from the default, it will be "Last", which means the score will be updated regardless. You can change your leaderboard settings in the Leaderboards tab in the Game Manager for your title - just select the leaderboard and click on the edit button.

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.