Forums > Javascript

Best way to perform functions on other unnamed(?) patchers/objects

Dec 30 2013 | 1:48 am

I have one main patch, with a js file in it. How can I perform commands from my JS file on other objects in my patcher. For instance, in my patcher there is another patcher **not a subpatcher** I dragged in with the name (in the max box, not scripting name) "patchtwo". How do I address it from javascript, to make new objects inside it or output messages from it?

To assign a variable name to my js object I have just written var x=this; which gives the js object the global variable name "x". I can then use its outlets, or create new objects from other js patches just by writing x.outlet(0,"bang"); How can I assign a variable name like this to the other patches in in my Max session (both subpatchers and normal)?

When I **create** the objects from js it is easy, because I can say z=this.patcher.newdefault(20,200,"message"); and the message box will be called z, but what about objects already made from the palette?

Dec 30 2013 | 2:59 am

you need to name your patcher with scripting name ;

var sp = this.patcher.getnamed("yourSubpatcherScriptingName").subpatcher()

your "sp" is a bridge to the objects inside your subpatcher . as patcher inside a patcher is a subpatcher anyway . no ?

Dec 30 2013 | 11:16 am

Okay, I think I see!! Thank you for your clarification.

So then, to create a message box in that subpatcher the code would be:
var sp = this.patcher.getnamed("yourSubpatcherScriptingName").subpatcher()
var myMessage=sp.newdefault(30,100, "message");

And if there were a number box with varname "mm" would it be set at

Can you explain why the documentation says "If the object contains a patcher, this function returns a (Javascript) Patcher object." Isn’t the object itself a patcher rather than "containing" a patcher. Is there any difference between a patcher object and a Javacsript Patcher object?

And yes, I guess that a patcher inside a patcher is a subpatcher (duh!), I just got confused because rather than making a patcher object (and typing p newPatcher), I just used a patcher I made that was saved in the search path.

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

Forums > Javascript