question

Jeremy Rigaud avatar image
Jeremy Rigaud asked

cloudscript not creating all PlayerData Key

Hey, I have done an Handler to create initial Data for new player, but only "Level" key is set, what I have done wrong ?
handlers.newplayer = function (args, context) {
                
var TitleData = server.GetTitleData({Keys: null}); var CurrentSeason = "Season_" + TitleData.Data["CurrentSeason"]; //New Player Data
var dataRequest = {
PlayFabId: currentPlayerId,
Data: {
"Level": 1,
[CurrentSeason]: {
"Rank":0,
"RemainingPlacementMatch":TitleData.Data["NeededPlacementMatch"]
}
}
};
server.UpdateUserData(dataRequest); return { "Data": dataRequest };

};

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

·
Citrus Yan avatar image
Citrus Yan answered

The value for the key “CurrentSeason” has to be a string in order for PlayFab to handle. Therefore, you should convert that JavaScript object into a string, for instance, with JSON.stringify(), before parsing it to the key “CurrentSeason”. I made some changes to your code, which works as expected:

handlers.newplayer = function (args, context) {
    var TitleData = server.GetTitleData({Keys: null});    var CurrentSeason = "Season_" + TitleData.Data["CurrentSeason"];    //New Player Data
    var dataRequest = {
        PlayFabId: currentPlayerId, 
        Data: {
            "Level": 2,
            [CurrentSeason]: JSON.stringify({
                "Rank":0,
                "RemainingPlacementMatch":TitleData.Data["NeededPlacementMatch"]
            })
        }
    };
    server.UpdateUserData(dataRequest);      return { "Data": dataRequest };
}

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.

Jeremy Rigaud avatar image Jeremy Rigaud commented ·

Thanks a lot, I dind't try this :)

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.