patcher.parentpatcher is null

Thomas's icon

Why does my parent patcher not exist when using this code:

function test() {
    post(patcher.parentpatcher.name);
}

test();

while it exists when using a 0 ms delay via a Task object?

function test() {
    post(patcher.parentpatcher.name);
}

tsk = new Task(test, this);
tsk.schedule(0);

do.while's icon

try to execute this code with loadbang . It may be that some of the objects/patchers are not yet registered , it may be that your JS object is initialized before parent patcher (?) .
Its better to search for objects after they are all created/registered .
Task will work because its scheduled .so it waits until other thread is free .

Thomas's icon

Thanks for the info,

loadbang() seems to be too early as well in this situation.

It's not a problem, just me trying to understand the inner workings of the javascript API.

do.while's icon

as for the info ...
try to experiment with loadbang sent to JS object ,and use bang() function inside to collect patcher object instances.
if its still too early then try deferlow your Max loadbang before sent to JS object .
if it also doesnt help ,then use delay object :D .
yeah its a little bit of pain but should work .

if u are using M4L the u can take advantage of live.thisdevice object in max ,which is sending bang as soon as all objects instatiate . its different than max loadbang

#EDIT
the Task hack seems to be nice solution too , thanks for that