question

Kim Strasser avatar image
Kim Strasser asked

server.GetLeaderboardAroundUser doesn't return the player's current highscore

I use CloudScript to update my leaderboard. But server.GetLeaderboardAroundUser always returns the player's last highscore and not his current highscore.

For example:

1) The client calls the CloudScript the first time after the reset of the leaderboard:

args.Playerscore = 12

element.StatValue.toString() = 0

2) The client calls the CloudScript the second time:

args.Playerscore = 16

element.StatValue.toString() = 12

3) The client calls the CloudScript the third time:

args.Playerscore = 20

element.StatValue.toString() = 16

Why is element.StatValue.toString() not returning the player's current highscore?

handlers.UpdateLeaderboard = function (args, context)
{
  var AddScore = UpdatePlayerScore(args.Leaderboardname, args.Playerscore);
  var CurrentScore = "";
 
  if (AddScore.leaderboardupdated == true)
      log.info("User statistics updated.");
  else
      log.info("Could not update statistics.");
  
  var resultleaderboard = server.GetLeaderboardAroundUser(
  {
      PlayFabID: currentPlayerId,
      StatisticName : args.Leaderboardname,
      MaxResultsCount : 1,
      ProfileConstraints: {
            ShowDisplayName : true
            }
  });
        
  if ((resultleaderboard != null) && (resultleaderboard.Error == null))
  {
      resultleaderboard.Leaderboard.forEach(element => {
      if (element.PlayFabId == currentPlayerId)
      {
          var PlayerPosition = element.Position + 1;
          CurrentScore = PlayerPosition + " " + element.Profile.DisplayName + " : " + element.StatValue.toString();
          return;
      }
      });
  }
  else
      CurrentScore = "Something went wrong. Could not get leaderboard highscore.";
        
  return CurrentScore;
}

function UpdatePlayerScore(leaderboardname, score)
{
    var result = server.UpdatePlayerStatistics({
           PlayFabId: currentPlayerId,
           Statistics : [{ StatisticName : leaderboardname, Value : score }]
           });
        
    if (result.Error == null)
        return { leaderboardupdated: true };
    else
        return { leaderboardupdated: false };
}
CloudScript
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

·
Seth Du avatar image
Seth Du answered

I have tried to reproduce your issue and here is my testing result. First, UpdatePlayerStatistics call is made, shortly, I call GetLeaderboardAroundUser API for few times and result will be different and it varies between the new version and last version. After few seconds, the callback will constantly return the new version. This is because the statistics/leaderboard need times to sync on all shards of PlayFab Servers and when you require the data via APIs, there can be delay between different shards, and this will take few times for all shards got synced. You will get the new version constantly after few minutes.

In terms of the leaderboard resetting. The reset process may take some time if the number of players is large. But after few minutes, the process should be done. May I ask what’s the time interval when you test GetLeaderboardAroundUser after reset?

2 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 ·

The reset frequency is "hourly" and aggregation method is "maximum". But I chose "hourly" just for testing, I think I will use "weekly" in my game.

Is it allowed to call GetLeaderboardAroundUser or GetLeaderboard more than once in a minute? How often can I call GetLeaderboardAroundUser or GetLeaderboard in a certain time interval? Is there a limit?

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

Hourly and weekly both should be fine. For most of data retrieval API calls, the limits are more sufficient than updating/modifying related APIs. However, the detailed limits seem to be not given. Getting leaderboard once for a minute should work fine.

In terms of getting last version of Statistics issue. You may try to get leaderboard few minutes later after a new version is updated. Feel free to tell us if there are still any other issues.

0 Likes 0 ·

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.