question

doronhn avatar image
doronhn asked

update user data (Json) with cloud script

Hey,

For every user that's play my game i store a user read only data that's look like this.

This content holds the progress of the user at specific level, for instance in the following JSON you can see that in level 1 (ID : 1) the user didn't get any start and etc.

{
  "PlayerLevelsList": [
    {
      "ID": "1",
      "Stars": "0",
      "PowerupsTaken": {
        "Teleport": 0,
        "Undo": 0,
        "TileStamp": 0,
        "Hint": 0
      }
    }
  ]
}

i want to update this JSON from cloud script, and add another item for this PlayerLevelsList.

{
  "PlayerLevelsList": [
    {
      "ID": "1",
      "Stars": "2",
      "PowerupsTaken": {
        "Teleport": 1,
        "Undo": 2,
        "TileStamp": 0,
        "Hint": 0
      }
    },
    {
      "ID": "2",
      "Stars": "0",
      "PowerupsTaken": {
        "Teleport": 4,
        "Undo": 0,
        "TileStamp": 0,
        "Hint": 0
      }
    }
  ]
}

how do i do that?

what do i need to send from the client?

is there any code example?

Player DataCloudScript
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

I'm afraid I don't understand the question. The data update calls available in our Client and Server SDKs let you update the player data trivially, and at any time. Are you having trouble using our API calls? If so, what Title ID and PlayFab ID(s) are you using for your test, and what is the error message you're getting back from the service?

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

doronhn avatar image doronhn commented ·

Hey,

thanks for the fast reply.

as i wrote i have user data that i want to update.

the data is a json array.

i want to add another item to that array and in addition change value of the current item. how do i do that on cloud script?

all i want tin excample.

thanks.

0 Likes 0 ·
brendan avatar image brendan doronhn commented ·

Sure, have a look at processPlayerMove in the basic Cloud Script that is loaded as revision 1 in all titles. It shows taking a JSON object (the event data taken from a move event) and writing it to the user data. You need to stringify the Value you're passing in for a given Key, since player data is stored as a string.

Alternately, you could use Entity Objects, which are JSON objects themselves. This tutorial shows how to use that functionality: https://api.playfab.com/docs/tutorials/entities/getting-started-entities

0 Likes 0 ·
doronhn avatar image doronhn brendan commented ·

i will check thanks.

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.