Save Multiple Custom Plugin Settings
-
In my project I'm using the below code (as an example) to save a global plugin setting. I'd like to add a few other settings to the file rather than create a new JSON for each setting but it seems the dumpAsJSON function only allows one argument, so what's the best way to achieve this?
if(Engine.loadFromJSON("..//MySettings.js") == undefined) { SETTING1.setValue(0); SETTING1.changed(); Engine.dumpAsJSON({"setting1": 1}, "..//MySettings.js"); } inline function onSETTING1Control(component, value) { Panel1.showControl(value); Engine.dumpAsJSON({"setting1":value}, "..//MySettings.js"); }; Content.getComponent("SETTING1").setControlCallback(onSETTING1Control);
-
err ... you can have as many "arguments" in a JSON file as you like...
if(Engine.loadFromJSON("..//MySettings.js") == undefined) { SETTING1.setValue(0); SETTING1.changed(); SETTING2.setValue("hello"); SETTING3.setValue(27); Engine.dumpAsJSON({"setting1": 1,"setting2": "Hello", "setting3":27 }, "..//MySettings.js"); }
-
though you are probably better off doing it this way:
reg myJSONObj = Engine.loadFromJSON("..//MySettings.js") ; if(myJSONObj == "") { myJSONObj = { "setting1": 1, "setting2": "Hello", "setting3":27 }; Engine.dumpAsJSON(myJSONObj , "..//MySettings.js"); }; inline function onSETTING1Control(component, value) { Panel1.showControl(value); myJSONObj.setting1 = value; Engine.dumpAsJSON(myJSONObj, "..//MySettings.js"); };
-
@Lindon ah I was trying it with parenthesis, thanks!