question

yzx2002 avatar image
yzx2002 asked

How to update multiple value for player statistic in cloud script?

I followed the cloud script example to update player statistics, but it didn’t create statistic data for player.


var updateStatistics = server.UpdatePlayerStatistics({
PlayFabId: currentPlayerId,
Statistics: [{
"StatisticName": "xp",
"Value": 0
}, {
"StatisticName": "level",
"Value": 0
}, {
"StatisticName": "achievement",
"Value": 0
}]
});

What's wrong in my code?

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

Actually, that worked fine for me:

handlers.Test = function(args) {
  var updateStatistics = server.UpdatePlayerStatistics({
    PlayFabId: currentPlayerId,
    Statistics: [{
      "StatisticName": "xp",
      "Value": 0
    }, {
      "StatisticName": "level",
      "Value": 0
    }, {
      "StatisticName": "achievement",
      "Value": 0
    }]
  });
}

What is the Title ID you're using for this test?

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

yzx2002 avatar image yzx2002 commented ·

title id is 7FB0, I tried again but still fail

// Triggerd when player login the game for the first time
 handlers.StartSetup = function(args) {
    // Add user data
    var setUserData = server.UpdateUserData({
        PlayFabId: currentPlayerId,
        Data: {
            "Skill1": "default",
            "Skill2": "default",
            "Skill3": "default",
            "Gender": "Male",
            "Name": "currentPlayerId"
        },
        "Permission": "Public"
});
    // Like AddUserVirtualCurrency, it's safer to call UpdatePlayerStatistics from CloudScript
        var updateStatistics = server.UpdatePlayerStatistics({
          PlayFabId: currentPlayerId,
          Statistics: [{
            "StatisticName": "xp",
            "Value": 0
          }, {
            "StatisticName": "level",
            "Value": 0
          }, {
            "StatisticName": "achievement",
            "Value": 0
          }]
        });
}
0 Likes 0 ·
brendan avatar image brendan yzx2002 commented ·

Looking at your title, the problem is that you already have a Statistic named "Achievement", and another named "Level". The StatisticName is case-sensitive, but we don't allow achievements that are identical in a case-insensitive check, so you can't create stats named "achievement" and "level". We'll be improving debugging of Cloud Script in the Game Manager as soon as we can, but for now, I would recommend checking the results in Postman if you're not getting all the details back from errors when running in the Game Manager.

0 Likes 0 ·
yzx2002 avatar image yzx2002 brendan commented ·

Do you mean the statistic is not own by player but the title? not like player data, so one title can only have one set of statistic?

0 Likes 0 ·
Show more comments
Show more comments

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.