Engine.loadFromJSON if undefined...
-
I use Engine.loadFromJSON to load a settings file to configure a few bits and pieces. I'm trying to add a new line of data (not normally an issue) but in this case I want something to happen if the data doesn't exist (yet). So for new users this works fine but for existing users who already have a Settings.json file but which doesn't contain the new line of data I can't find a way of checking if the data exists or not and, if not, doing something... Any ideas welcome! My script below....
reg myJSONObj = Engine.loadFromJSON("..//Settings.js"); if(myJSONObj == "") { myJSONObj = { "analysers": 1, "nodes": 1, "lock": 0, "newthing": 1 }; Engine.dumpAsJSON(myJSONObj , "..//Settings.js"); }; inline function checkOnLoadSettings() { local data = Engine.loadFromJSON("..//Settings.js"); if ((data.newthing) !isDefined) //if (data.newthing == "") { newthing.showControl(1); }
-
@DanH said in Engine.loadFromJSON if undefined...:
if ((data.newthing) !isDefined)
isDefined is a function.
if (!isDefined(data.newThing))
-
@d-healey said in Engine.loadFromJSON if undefined...:
if (!isDefined(data.newThing))
Hmmm... I had tried that. No errors but doesn't do the new thing either....
EDIT - Actually I'd already written some other stuff below which cancelled out the changes to this if statement
So it did work, thanks for confirming!!