Programmatically messaging a specific inlet on a JavaScript-created object

    Javascriptadvanced

    Eric Lyon
    Oct 02 2018 | 1:50 am
    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

    • jbone1313's icon
      jbone1313
      May 31 2023 | 4:13 pm
      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.
      Share
    • Eric Lyon's icon
      Eric Lyon's icon
      Eric Lyon
      May 31 2023 | 5:01 pm
      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
      Trevor being Trevor's icon
      Trevor being Trevor
      Jun 20 2023 | 10:35 pm
      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