find and return scripting name of specific object issue.


    Aug 18 2013 | 8:00 pm
    Hi guys,
    I'm getting back into js again to scrape data on some of my patches for a sort of adaptive master control patch.
    Anyway the first problem I've come into is in the code below.
    From my understanding (providing my patch has a pattrstorage in it, which it does) the variable 'thePattr' should be assigned to the return value of the 'findPattr' function surely?
    Unless I've misunderstood something about returns.
    I seem to get undefined.
    However, if I put 'post("pattrName " + a.varname);post();' before returning in the 'findPattr' function I get the scripting name I'm looking for.
    Any ideas?
    function getPattr(){
    var thePattr = this.patcher.apply(findPattr);
    post("thePatt " + thePatt.varname);post();
    }
    function findPattr(a){
    if (a.maxclass === "pattrstorage") {
    return a;
    }
    }

    • Aug 18 2013 | 8:26 pm
      Apologies, obvious typo, the problem still remains:
      function getPattr(){
      var thePatt = this.patcher.apply(findPattr);
      post(“thePatt ” + thePatt.varname);post();
      }
      function findPattr(a){
      if (a.maxclass === “pattrstorage”) {
      return a;
      }
      }
    • Aug 19 2013 | 8:12 am
      Hi, the call to apply is not going to return the instance you are expecting, you need to perform all the logic inside your findPattr() function,
      i.e.
      function findPattr(a){
      if (a.maxclass === “pattrstorage”) {
      // do your logic here
      }
      }
      L