Simple but head-aching connect() issue, urgent!


    Apr 21 2006 | 3:15 pm
    Hi everyone
    Sorry for troubling you with such simple questions, but I spend hours on the problem and I couldn't find any answers on the mailing-list or in the JavaScriptInMaxPDF. Please!
    I create a gate object in js, like this: var theGate = this.patcher.newdefault(100 , 100, "gate");
    Now, I want to connect it to an dac~ obect i created in Max and named (via. name...) "theDac", and I guess Im supposed to do like this: this.patcher.connect(theGate, 0, theDac, 0);
    I get the error "Javascript ReferenceError: theDac is not defined".
    ...why?
    ~Carl Email

    • Apr 21 2006 | 5:45 pm
      what you set in Max-land is the "varname" property, and what the function "connect" uses is a javascript representation of a max object, very different.
      you need this code (or something similar) to get the js max object associated with the varname "theDac":
      var jsDac = this.patcher.getnamed("theDac"); this.patcher.connect(theGate, 0, jsDac, 0);
      -evan
    • Apr 22 2006 | 7:30 am
      Thank you Evan
      I tried getnamed() like you propose, but then Max crashes when I connect(). If I ask for the content of jsDac by post(jsDac) I get the reply "jsobject 0". Any ideas?
      ~Carl Email
    • Apr 22 2006 | 8:36 am
      If you post an example patch and JS file it will be much easier to help.
      best, wes
    • Apr 22 2006 | 8:41 am
      Is your "theDac" in the same patcher level as the js object? It should work then. Maybe try a different name? If you don't want max to crash do something like this:
      if(jsDac){ //connect } else post("can't find dac!n)"
      Deleting or connecting objects that don't exist leads to crashes in js, so you have to always check for yourself. I'd like to see this get changed to a friendly error message one day..:-). thispatcher scripts don't crash on these things.
      hth, Thijs
    • Apr 22 2006 | 9:23 am
    • Apr 22 2006 | 9:41 am
      If you want help with your old patch explain what's bugging you or send the patch and I'll have a look. Otherwise good luck.
      Best, Thijs