HISE Logo Forum
    • Categories
    • Register
    • Login

    Namespace != object

    Scheduled Pinned Locked Moved General Questions
    25 Posts 3 Posters 1.1k 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.
    • LindonL
      Lindon @Christoph Hart
      last edited by Lindon

      @Christoph-Hart yes - both these post pretty much sum up the problem:

      var myTester = eval(Engine.loadFromJSON("test2.js"));
      

      where test2.js =

      {
        "soundName": "S",
        "group": 17,
        "planSet": [
          {
            "soundName": "B",
            "group": 2,
            "preWait": {
              "minVal": 4,
              "currentVal": 10,
              "maxVal": 25
              },
            "postWait": {
              "minVal": 1,
              "currentVal": 1,
              "maxVal": 1
            },
            "aCurve": 0.5,
            "aTime": 0,
            "aLevel": 0,
            "hTime": 100,
            "dCurve": 0.43,
            "dTime": 50,
            "sLevel": 100,
            "rTime": 0
          }
        ]
      };
      

      results in myTester =

      {
        "dump": Method,
        "clone": Method
      }
      

      So we see LoadFromJSON will not load any kind of object......unless I'm doing something silly(quite possible)

      and
      "But isn't the only problem the fact that you put a function into the object? JSON is a data format so you can't put logic in it..."

      So yes JSON definitely ISNT working properly, and even if it was then it wouldnt do whats needed here. However there is a way to "unserialise" a string into an object WITH its functions, as well as a way to serialise an object WITH its functions

      Just theres no way to save a string in HISE....

      Hold on I WAS doing something silly...that eval is not required....stiull I'd like a way to serialise and unseralise WITH functions and we seem to be most of the way there... 'cept for save and load string...

      HISE Development for hire.
      www.channelrobot.com

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        I can't speak about eval because this is an easter egg that David found by accident :)

        But the normal JSON dump method works as it should:

        var x = {
            "obj1": [12, 15, 16],
            "p2": ["alpha"]
            
        };
        
        Engine.dumpAsJSON(x, "myTest");
        
        var y = Engine.loadFromJSON("myTest");
        

        Look at y in the object viewer (right click on the row in the scriptwatch table). You'll see that it perfectly clones the x object via the external file.

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

          @Christoph-Hart yeah _ I think I got there before you - me being silly - it works for objects as long as they are just data, so not really objects just structs really... so I guess I'm back to having some external function for every method I want on an object I would like to "save" - its messy. Back to looking at namespaces again...

          HISE Development for hire.
          www.channelrobot.com

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            But why is that messy? You most definitely don't want logic code in a user readable JSON dump? And if you rewrite the function

            inline function saveTargetPlan(obj, target)
            {
                for (p in obj.planSet) // changed it to a range-based loop for you ...
                {
                    if (p.soundName == target)
                        return p;
                }
            }
            

            and put it in a separate file with proper namespacing, I don't see how it can be more messy than the other solution...

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

              @Christoph-Hart well you're going to have to excuse me I'm an old SmallTalk programmer - encapsulation is nearly everything...

              HISE Development for hire.
              www.channelrobot.com

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

              26

              Online

              1.8k

              Users

              12.1k

              Topics

              105.5k

              Posts