Patcher properties example script

Jan 21, 2007 at 12:40pm

Patcher properties example script

Hi, the example script provided in Basic Javascript programming -> Patcher properties -> box seems to be incorrect.

It reads like this:

prev = 0;
owner = this.patcher.box;
while (owner)
{
prev = owner;
owner = owner.patcher.box;
}
if (prev)
post(“top patcher is”,prev.name);

But prev (being a Maxobj) doesn’t have the propery ‘name’. Also, the topmost patcher object doesn’t return a ‘box’ property, so this loop quits one cycle too early.

To reproduce:

save as ‘top.js’:

autowatch= 1
outlets= 1;
inlets=1 ;

function top()
{
prev = 0;
owner = this.patcher.box;
while (owner)
{
prev = owner;
owner = owner.patcher.box;
}
if (prev) post(“top patcher is”,prev.name);
}

#N vpatcher 28 242 214 370;
#P window setfont “Sans Serif” 9.;
#P message 33 40 22 196617 top;
#P newex 33 58 48 196617 js top.js;
#P connect 1 0 0 0;
#P pop 1;
#P newobj 35 47 39 196617 p yeah;

This outputs in the max window: top patcher is

Now try this for ‘top.js’:

autowatch= 1
outlets= 1;
inlets=1 ;

function top()
{
prev = 0;
owner = this.patcher.box;
while (owner)
{
prev = owner;
owner = owner.patcher.box;
post(“prev: ” + prev.subpatcher().name + “, new owner: ” + owner);
post();
}
if (prev) post(“top patcher is”, prev.name);
}

This returns:

prev: yeah, new owner: undefined
top patcher is

Mattijs

#29843

You must be logged in to reply to this topic.