Creating objects in other patchers with javascript

Nov 24, 2009 at 4:01am

Creating objects in other patchers with javascript

Hello,

I’d like some help with how to create objects in other patchers with javascript. I know how to do it in the same patcher with the this.patcher.newdefault or newobject command, but I can’t figure out how to do it in other patchers.

Thanks

#46693
Dec 3, 2009 at 6:33pm

You can iterate through open patches using the next property of the Wind object.

It is a bit tricky but something like this could simplify it (not tested!):

function getOpenPatcherNamed(name) {
    var wind = patcher.wind;
    var test = wind.next;
    while (test.assoc.name != name) {
        if (test = wind.next) {
            return null;
        }
    }
    return test.assoc;
}

togglePatch = getOpenPatcherNamed("togglepatch");

togglePatch.newdefault(10, 10, "toggle");
togglePatch.newdefault(30, 10, "toggle");
togglePatch.newdefault(40, 10, "toggle");
#167954
Dec 3, 2009 at 6:35pm

Error spotted, the function should go like this…

function getOpenPatcherNamed(name) {
    var wind = patcher.wind;
    var test = wind.next;
    while (test.assoc.name != name) {
        if (test = wind) {
            return null;
        }
    }
    return test.assoc;
}
#167955

You must be logged in to reply to this topic.