question

george@thenuum.com avatar image
george@thenuum.com asked

Serializing Custom data for inventory instance with cloudscript

We have players that own cosmetics. Cosmetics are inventory items. Each cosmetic can have up to 14 variants. So we store variants unlocked as an int array. 0 for unlocked and 1 for locked.

We use a cloudscript to unlock the variant. I am not very familiar with serializing objects in cloudscript. I assume that I need to serialize the int array before putting it into dataPayload. Or would an array of strings work instead?
6187-image.png

CloudScriptPlayer Inventory
image.png (25.7 KiB)
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

·
Neils Shi avatar image
Neils Shi answered

Here is an example of cloudscript you can refer to:

 handlers.UnlockCosmetics = function(args,context)
 {
     var variantUnlocked = args.variantIndex;
     var unlockCosmetics = args.unlockCosmeticsObject;
        
     var unlockCosmeticsObject;
     unlockCosmeticsObject = JSON.parse(unlockCosmetics);
     unlockCosmeticsObject[variantUnlocked] = 1;
        
     var dataPayload = {"variants":JSON.stringify(unlockCosmeticsObject)}
        
      server.UpdateUserInventoryItemCustomData({
         PlayFabId:currentPlayerId,
         ItemInstanceId:args.ItemInstanceId,
         Data : dataPayload
     });
 }

And you can also refer to my testing request body of API ExecuteCloudScript:

 {
   "FunctionName": "UnlockCosmetics",
   "FunctionParameter": 
   {
     "variantIndex": "2",
     "ItemInstanceId": "F41F6Cxxxxxxxxx",
     "unlockCosmeticsObject": "[0,1,1,0,1]"
   },
   "RevisionSelection": "Live",
   "GeneratePlayStreamEvent": true
 }
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.