Forum

    • Register
    • Login
    • Search
    • Categories

    Save Multiple Custom Plugin Settings

    General Questions
    2
    4
    46
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DanH
      DanH last edited by

      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);
      
      1 Reply Last reply Reply Quote 0
      • Lindon
        Lindon last edited by

        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");
        
        }
        

        HISE Development for hire.
        www.channelrobot.com

        Lindon 1 Reply Last reply Reply Quote 0
        • Lindon
          Lindon @Lindon last edited by Lindon

          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");
              
          };
          

          HISE Development for hire.
          www.channelrobot.com

          DanH 1 Reply Last reply Reply Quote 1
          • DanH
            DanH @Lindon last edited by

            @Lindon ah I was trying it with parenthesis, thanks!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            20
            Online

            982
            Users

            6.6k
            Topics

            60.8k
            Posts