question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

Do statistics update immediately? (Not leaderboards)

Hello,

I was wondering when I use UpdatePlayerStatistics function in Cloudscript, does the value is updated in the player's data (not in leaderboard) immediately if there are many players?

For example, in this code:

    var getOtherUserStatistic = {
        "PlayfabId": args.ID,
        "StatisticNames": ["Score"]
    };
    var getOtherUserStatisticResult = server.GetPlayerStatistics(getOtherUserStatistic);
    
    if(parseInt(args.Score) > parseInt(getOtherUserStatisticResult.Statistics[0].Value)) {
        // ... do something
    }
    
    var updateMyStats = {
        "PlayFabId": currentPlayerId,
        "Statistics": [{
            "StatisticName": "Score",
            "Value": args.Score
        }]
    };
    server.UpdatePlayerStatistics(updateMyStats);

Let's say the Player1's score is 10 and Player2's score is 5. When the Player1 calls this function with a score parameter of 15, the function will check the new score and Player2's score. In this case, "15 > 5" condition will be true, so that the funtion will execute the code that is in the if statement. Afterwards, the statistic will be updated and the Player1's score will be 15.

Right after the function is finished, let's say the Player2 calls this function with a parameter of 12. In this case, when the function gets the Player1's score, will it return 10 or 15? So will the if statement be "12 > 10" or "12 > 15"? Is there any delay in updating statistics (not leaderboard).

I saw some post that there is a delay in leaderboards when there are many players. I was wondering if there is the same thing for updating statistics when there are many players?

Even if there is any 1-2 seconds delay, it is important to me. If there is, I'm going to change the logic with read only data but that increases the number of API call and repeats the same data in both statistics and read only data.

Alternative solution:

    var getOtherUserData = {
        "PlayfabId": args.ID,
        "Keys": ["Score"]
    };
    var getOtherUserDataResult = server.GetUserReadOnlyData(getOtherUserData);
    
    if(parseInt(args.Score) > parseInt(getOtherUserDataResult.Data["Score"].Value)) {
        // ... do something
    }
    
    var updateMyStats = {
        "PlayFabId": currentPlayerId,
        "Statistics": [{
            "StatisticName": "Score",
            "Value": args.Score
        }]
    };
    server.UpdatePlayerStatistics(updateMyStats);
    
    // I need to update the caller's read only data as well because of the delay. Extra API call.
    var updateMyData = {
        "PlayFabId": currentPlayerId,
        "Data": {
            "Score": args.Score
        }
    };
    server.UpdateUserReadOnlyData(updateMyData);
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

PlayFab is based on RESTful API and HTTP request reliability depends on many factors. During my test, Statistics will update immediately, but we cannot guarantee the same result in different network environment by different ISP.

I believe your scenario is to compare the Statistics before player can update the new score. If you have specific requirement, you may consider using hosted dedicated multiplayer servers.

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.