question

Kytan avatar image
Kytan asked

UpdateUserData bug?

I have this function that basically copies whatever the player has in their tags to the User Data but something strange is happening, when I call the function it works, but the Key always ends with [0], I just want the key to be "Sensitivity"

This is the function:

 handlers.saveSensitivityFromTagsToUserData = function (args, context) {
        
     var getPlayerTagsResponse = server.GetPlayerTags({ "PlayFabId": currentPlayerId })
        
     var foundTags = JSON.parse(JSON.stringify(getPlayerTagsResponse.Tags).replace('title.528BC.', ''))
        
     var updatePlayerDataResponse = server.UpdateUserData({"PlayFabId": currentPlayerId, "Data": {"Sensitivity": foundTags}, "Permission": "Public"})
        
     return foundTags;
        
 }
Player DataCloudScriptPlayStream
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

·
Simon Cui avatar image
Simon Cui answered

User Data is arbitrary string/string key/value pair data, so what you need to do is stringify the array before you send it up as the value for the key, instead of parsing the Json string to Object via JSON.parse. For your codes, I recommend modifying the line 4 as following:

 var foundTags = JSON.stringify(getPlayerTagsResponse.Tags).replace('title.528BC.', '')
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.