access data from a different subpatcher?

Feb 5, 2010 at 8:18pm

access data from a different subpatcher?

I’m writing a javascript function in one of my subpatchers that needs to grab an array from js files in several other subpatchers. Basically I need to route the function call up to the parent patcher and then back down to a different subpatcher. What’s the syntax for doing that? I saw some forum threads with a convoluted way to do so in 4.6 which hinted that there would be a much easier way to do so in 5. Is that true? What’s the best syntax to use to perform this action? Thanks!

#48264
Feb 5, 2010 at 9:21pm

Just use globals rather than local vars. Javascript globals in Max are truly global – i.e. they can be accessed in any js script.

#173582
Feb 5, 2010 at 9:58pm

Thanks, I was hoping such a thing was possible. From the tutorial on globals, I got the impression they were only good for sending messages between patchers, not accessing variables. Could you provide an example of how to, for example, declare a global array, and then access it?

#173583
Feb 5, 2010 at 11:02pm

If I remember correctly you just would declare your array without the var prefix in one script, then access it by name in the other.

foo = new Array[];

—————-

var localVar = foo[x];

#173584
Feb 5, 2010 at 11:50pm

Wow – well that’s pretty cool. Wish I’d known about that a while ago :-) Thanks for the help Jesse!

#173585
Feb 6, 2010 at 10:38pm

I would recommend going the Global object route. it’s the cleanest way. Omitting the var keyword is more like a hack.

#173586
Apr 30, 2010 at 8:54pm

What ej means is of course: create one unique object with the name of your project and use its properties. All globals are dangerous, but one is better than many.

#173587
Apr 30, 2010 at 9:08pm

This is the most concise and complete discussion of local/global scope in Javascript I’ve found.

http://www.irt.org/script/1321.htm

Agreed that it’s cleaner to create a single global object and set/get its properties in all scripts. But it’s still useful to know the implications of the var keyword within functions.

#173588
May 1, 2010 at 7:52pm

I meant the Global object which is a standard Max / JS way of sharing / setting data between Max and JavaScript.

#173589
May 4, 2010 at 3:29pm

Emmanuel, that the docs of that object is not visible from the Javascript in Max page. I see that the “Global object” link erronously points to
http://www.cycling74.com/docs/max5/vignettes/js/jsglobal.html instead of http://www.cycling74.com/docs/max5/vignettes/js/jsglobalobject.html.

That explains why I never heard about it ;)

#173590

You must be logged in to reply to this topic.