Re: javascript patcher.firstobject help... anybody...


    Dec 20 2005 | 9:56 pm
    Actually I tried making firstobject and nextobj methods but MAX
    tells me that they are not functions. Any other ideas why this
    does not work?
    Anthony

    • Dec 20 2005 | 10:42 pm
      functions in javascript use parentheses to pass arguments to the
      function. however, even if you are not passing arguments to the
      function, you need to use an empty pair of parentheses. this tells
      the script that you are trying to call a function and not reference a
      property. in other words, change your code to this:
      obj = this.patcher.firstobject();
      while(obj)
      {
      outlet(0, obj.varname);
      obj = obj.nextobj();
      }
      -scott
    • Dec 20 2005 | 10:48 pm
      On Dec 20, 2005, at 1:56 PM, apalomba@austin.rr.com wrote:
      > Actually I tried making firstobject and nextobj methods but MAX
      > tells me that they are not functions. Any other ideas why this
      > does not work?
      They are both *properties*, but please notice your typo. It is not
      "nextobj", but "nextobject" as documented in the latest
      JavascriptInMax.pdf. The following code works fine for me under OS X
      10.4.3, and MaxMSP 4.5.6.
      var obj = this.patcher.firstobject;
      while(obj)
      {
      outlet(0, obj.varname);
      obj = obj.nextobject;
      }
      -Joshua
    • Dec 20 2005 | 10:49 pm
      Yes, I know. When I take the code just as you have it
      and run it Max, Max says that firstobject and nextobj
      are not functions.
      Anthony
    • Dec 20 2005 | 10:58 pm
      Ooops, he he he, thats what I meant.
      You mean Max, does not have any kind of AI
      to catch this error?! I am very disappointed in you Cycling74.
      Anthony
    • Jan 25 2006 | 12:30 am
      Okay so I am still having trouble with nextobject. When ever
      I run the following javascript, Max locks up.
      var obj = this.patcher.firstobject;
      while(obj != null)
      {
      outlet(0, "varname = " + obj.varname);
      obj = obj.nextobject;
      }
      It looks like the call to nextobject is causing the problem.
      Does anyone know what might be the problem?
      Anthony
    • Jan 25 2006 | 1:06 am
      anthony,
      have you tried joshua's suggestion which you quoted?
      perhaps the nextobject property for the last object isn't null. just
      try "while(obj)". this would explain max locking up, because you would
      be stuck in an endless loop.
      -jim
    • Jan 25 2006 | 1:18 am
      I tried while(obj) as well, it still locks up. I don't think it is in
      an endless loop because I should at least be seeing the output
      "varname = "
      Anthony
    • Jan 25 2006 | 9:56 am
      On around Jan 25, 2006, at 2:06, jim altieri said something like:
      > just
      > try "while(obj)".
      while (obj)
      and
      while (obj != NULL)
      are identical statements. The only difference is programming style (ie,
      lazy typing). If your Javascript/Java/C/C++ system doesn't generate
      identical code for both conditionals, you've got a buggy
      compiler/interpreter.
      That said, Anthony's code looks fine and I don't immediately see why it
      should lock up. Stupid question: are you very sure the syntax to the
      outlet() call is OK?
      -- P.
      -------------- http://www.bek.no/~pcastine/Litter/ --------------
      Peter Castine | ^
      | Litter Power & Litter Bundle for Jitter
      pcastine@gmx.net |
      pcastine@bek.no | iCE: Sequencing, Recording, and Interface Building
      4-15@kagi.com | for Max/MSP
      | Extremely cool
      | http://www.dspaudio.com
      | http://www.dspaudio.com/software/software.html
    • Jan 25 2006 | 10:53 am
      Well, I'd expect my Java compiler to reject both of them: the first
      unless obj is a boolean (or, under Java 1.5, a Boolean object with
      auto-unboxing) and the second unless NULL is defined and is
      compatible with the type of obj, since Java uses the lower-case form.
      nick rothwell -- composition, systems, performance -- http://
      www.cassiel.com
    • Jan 25 2006 | 2:44 pm
      On around Jan 25, 2006, at 11:53, Nick Rothwell said something like:
      > Well, I'd expect my Java compiler to reject both of them:
      Like I said, identical.
      -)
      -------------- http://www.bek.no/~pcastine/Litter/ --------------
      Peter Castine | ^
      | Litter Power & Litter Bundle for Jitter
      pcastine@gmx.net |
      pcastine@bek.no | iCE: Sequencing, Recording, and Interface Building
      4-15@kagi.com | for Max/MSP
      | Extremely cool
      | http://www.dspaudio.com
      | http://www.dspaudio.com/software/software.html
    • Jan 25 2006 | 4:20 pm
      Well I finally got it to work, this is what it looks like:
      var obj = this.patcher.firstobject;
      while(obj != null)
      {
      nextobj = obj.nextobject;
      if(obj == nextobj )
      break;
      else
      obj = nextobj ;
      outlet(0, "varname = " + obj.varname);
      }
      But I don't understand why this does not work:
      var obj = this.patcher.firstobject;
      while(obj != null)
      {
      outlet(0, "varname = " + obj.varname);
      obj = obj.nextobject;
      }
      It would appear that there is a circular reference in
      the object list.
      Anthony