Programmatically messaging a specific inlet on a JavaScript-created object

Eric Lyon's icon

Greetings,

Is there a tight JavaScript methodology for sending messages into specific inlets of an object that was created with JavaScript code? The object might be a native Max object that has more than one inlet, or it might be an abstraction that needs to have messages sent not to the containing patcher, but into one of its inlets.

One could of course create a temporary message object, connect it to the inlet in question, set the message into the message object, bang the message into the desired inlet, disconnect the message object, and then remove it from the patcher. But that feels overly dramatic. It would be very enjoyable if a more direct approach were possible.

TiA,
Eric

Sonoran Music Devices's icon

Hi OP,

Did you ever figure out an elegant way to send messages to inlets via JavaScript?

I just bumped into this issue. I am trying to build a Max patch entirely (or as much as possible) in JavaScript, and this issue has become a major impediment.

Any code examples you have would be much appreciated.

Thank you.

Eric Lyon's icon

I never saw an update for JavaScript in Max to provide this functionality. It would still be nice to have it.

Eric

Trevor being Trevor's icon

First, I would say yes, I have had to use the strategy of creating objects, connecting them to the js object, bang, then remove the object sometimes to accomplish certain tasks. However, for sending messages here's some extra options that may help...

exampleObject = this.patcher.newdefault(450, 36, "textbutton");

//is there an attribute you can set? Keep in mind that you can print the result of getattrnames to get a list
exampleObject.setattr("fontsize", 12);

//depending on the object you may be able to set the value directly
exampleObject.set(<value>);

This is kind of explained at the bottom of this documentation page
https://docs.cycling74.com/max8/vignettes/jspatcherobject