how to use this.patcher.message method… to send message to ANother patcher?

Apr 5, 2011 at 8:18pm

how to use this.patcher.message method… to send message to ANother patcher?

how to use this.patcher.message method… to send message to ANother patcher?

I have a subpatcher and want to send message from it, to the parent patcher.
I tried to put a global name on the parent patcher (main is a pretty name) and I tried the (probably awful) main.patcher.message()

nothing.

any tip?

#56111
Apr 5, 2011 at 9:44pm

You can’t use message() with a patcher object in javascript, it will only work for maxobj javascript objects within a patcher. Do you have an example patch, I’d be happy to have a look. Here’s an example that might help with a brief explanation which might shed some light on the subject:

this.patcher.parentpatcher.getnamed("objname").message("do this thing");

this.patcher: where we are right now.
.parentpatcher: get the patcher object of the containing patcher.
.getnamed("objname"): get the maxobj object with scripting name “objname” in the parent patch.
.message("do this thing"): send this message to the afore-mentioned object.

#201504
Apr 5, 2011 at 9:50pm

ok you just answered (parentpatcher)
I abused by saying that, but I know Maxobj is a representation of the patcher in JS.

In several line, you just taught me how to navigate in that case :)

thanks a lot Luke,
julien

#201505
Aug 11, 2011 at 4:15pm

That’s really helpful Luke. Is there a way to access subpatches as well?

#201506
Aug 12, 2011 at 7:29pm

You could, of course, add another outlet to your js object, connect it to a dedicated inlet in your subpatcher, and connect that inlet inside the subpatcher to a [thispatcher] object.

That buys you pretty much everything sending messages from inside your js can do, with the added advantage that you have some kind of visible connection in your patch reminding you (a year later, when you have to make changes to the patch) that you’re doing dynamic scripting from inside the js.

Invisible messages can make patch maintenance a nightmare. Arguably more so than the dreaded goto statement in procedural programming languages. They can be a powerful tool, but you can also shoot yourself in the knee with them.

If I seem a little obsessive about this, I have in the course of my career taken on maintenance for several large projects with upwards of 20 js files generating dynamic stuff, sometimes in great-grandparent patchers. It’s hell and mostly could be done in other, more maintainable ways.

#201507

You must be logged in to reply to this topic.