I've asked this question before, and got an answer but I'm going to try to articulate it better this time. I have a TitleData JSON object with about 20 nested keys. These are the first two out of twenty,
{ "Settler": { "id": 0, "rating": 0, "ratingTop": 49, "nextClass": "Rebellious" }, "Rebellious": { "id": 1, "rating": 50, "ratingTop": 99, "nextClass": "Fugative" }, }
Each player has a "Rating" statistic which has a rule in automation to call a cloudscript everytime the "Rating" statistic changes. My cloudscript function is below. It is messy... however its been changed a lot, trying to get different results.
handlers.UpdateSocialClass = function (args) { //Get current socialclass stored in currentSocialClass readonlydata var dataRequest = { PlayFabId: currentPlayerId, Keys: ["SocialClass"] }; var currentSocialClass = server.GetUserReadOnlyData(dataRequest); //get current rating stored in the var currentRating var statsRequest = { PlayFabId: currentPlayerId, StatisticName: "Rating", }; var currentRating = server.GetPlayerStatistics(statsRequest); //Get the title data for SocialClasses, stored in jsonObject var getTitleDataRequest = "SocialClasses"; var getTitleDataResponse = server.GetTitleData(getTitleDataRequest); //Access current class within the JSON object var yourSocialClassJson = getTitleDataResponse[currentSocialClass]; //Access ratingtop within the current class jsonObject var ratingCap = yourSocialClassJson.ratingTop; //If they have enough rating level up if(currentRating > ratingCap) { var newClass = yourSocialClassJson.nextClass; //set userdata to new class dataPayload["SocialClass"] = newClass; var result = server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Data: dataPayload }); } else { // If they have less than required amount then DownGradeSocialClass } }
In PlayStream it says my error is
"Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "TypeError: Cannot read property 'ratingTop' of undefined\n at handlers.UpdateSocialClass (95E3-main.js:89:41)"
I know this is most likely an easy fix. I assume my syntax is wrong when I get the title data or when I try to access the different values in title data. Debugging on cloudscript is a little difficult for me. Is there an easier way rather than playstream?