Re: javascript patcher.firstobject help… anybody…

Dec 20, 2005 at 9:56pm

Re: javascript patcher.firstobject help… anybody…

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

#24102
Dec 20, 2005 at 10:42pm

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

#69246
Dec 20, 2005 at 10:48pm

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

#69247
Dec 20, 2005 at 10:49pm

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

#69248
Dec 20, 2005 at 10:58pm

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

#69249
Jan 25, 2006 at 12:30am

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

#69250
Jan 25, 2006 at 1:06am

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

#69251
Jan 25, 2006 at 1:18am

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

#69252
Jan 25, 2006 at 9:56am

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

#69253
Jan 25, 2006 at 10:53am

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://
http://www.cassiel.com

#69254
Jan 25, 2006 at 2:44pm

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

#69255
Jan 25, 2006 at 4:20pm

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

#69256

You must be logged in to reply to this topic.