HISE Logo Forum
    • Categories
    • Register
    • Login

    Engine.loadFromJSON if undefined...

    Scheduled Pinned Locked Moved Scripting
    3 Posts 2 Posters 231 Views
    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.
    • DanHD
      DanH
      last edited by DanH

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

      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
      https://dhplugins.com/ | https://dcbreaks.com/
      London, UK

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @DanH
        last edited by

        @DanH said in Engine.loadFromJSON if undefined...:

        if ((data.newthing) !isDefined)

        isDefined is a function.

        if (!isDefined(data.newThing))

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        DanHD 1 Reply Last reply Reply Quote 0
        • DanHD
          DanH @d.healey
          last edited by DanH

          @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!!

          DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
          https://dhplugins.com/ | https://dcbreaks.com/
          London, UK

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

          53

          Online

          1.7k

          Users

          11.7k

          Topics

          101.8k

          Posts