Forums > Javascript

Creating objects in other patchers with javascript

November 24, 2009 | 4:01 am

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


December 3, 2009 | 6:33 pm

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");

December 3, 2009 | 6:35 pm

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;
}

Viewing 3 posts - 1 through 3 (of 3 total)