question

duartedd avatar image
duartedd asked

playfab serialization JSON

Hello

function UpdateQuestProgress(args) {
  var QuestDetails =  {
   LevelID :  args.LevelID,
   DifficultyCompleted : args.DifficultyCompleted
  };
  var QuestData = {
    args.LevelName : QuestDetails
  };
  var dataupdate = {};
  dataupdate["QuestLevelProgress"] =JSON.stringify(QuestData);
    var updateDataRequest = {
        PlayFabId: currentPlayerId,
        Data: dataupdate,
      Permission: "Public"
    };
    server.UpdateUserReadOnlyData(updateDataRequest);
  return true;
}


just wondering how i would get the args.LevelName to properly take as LevelName actually outputs "LevelName" I want the actual level name

also it looks like it overwrites data that already exists ( i can get around this by pulling the data then taking this on or something but is there any api calls that will Add an array to the userreadonlydata value if its not unique and itll update values if they are the same or something? otherwise i am going to have to extract the data run through it compare and such which means i am probably going to switch to a different quest system if thats the case one which is most likely point based or something where i can just increment.

for instance im trying to

key = questlevelprogress

value = {

"the giant" { completeddifficulty : 1, levelid 0}

}

and tack on
{"the rat" { completeddifficulty : 1, levelid 1} }

so

value = {

"the giant" { completeddifficulty : 1, levelid 0}, "the rat" { completeddifficulty : 1, levelid 1}

}

thanks for the help!

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

There's a complete example showing how to use dynamically-defined keys in Cloud Script in this thread: https://community.playfab.com/questions/83/205460148-Cloud-Script-how-do-I-write-data-to-a-Key-which-is-defined-dynamically.html

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.