Finding and named object from javascript


    Nov 19 2018 | 10:32 pm
    I have a bit of javascript code that I was using to find a named object. It appears no longer work now. Can someone please explain why this does not work anymore or if there is a better way to do this?
    function findObj(objname) { var root = this.patcher; while(root.parentpatcher != null) root = root.parentpatcher; var obj = root.firstobject; while(obj != null) { post(obj.varname + "\n"); if(obj.varname == objname) return obj; nextobj = obj.nextobject; if(obj == nextobj ) break; else obj = nextobj ; } return null; }

    • Nov 20 2018 | 10:36 pm
      What is the proper way to do this now?
    • Nov 21 2018 | 5:34 am
      Okay so it looks like this was some old code I had laying around that did not work. Here is the proper working code for finding a named object...
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////// function FindObj(objname) { return patcherTraverse(FindRoot().firstobject, objname); } function FindRoot() { var root = this.patcher; while(root.parentpatcher != null) root = root.parentpatcher; return root; } function patcherTraverse(obj, objname) { while(obj != null) { if(obj.varname == objname) { return obj; } var subp = obj.subpatcher(); if (subp) { var gotobj = patcherTraverse(subp.firstobject, objname); if (gotobj) { return gotobj; // only return if we got something! } } obj = obj.nextobject; } return null; }