Return values from max objects / Expose as attribute
When you create a max object in JS, and send it a message from JS to trigger one of its methods, is there a way to get to the values from the object outlets? As far as I'm aware there is no way to do this.
Assuming I'm correct, would the following work?
Write an object in C which does nothing but expose incoming data as a variable length list attribute. I'll refer to this object as [expose]. If you want to receive the return values from a max object in JS then you would
- connect the output from the target object to [expose]
- send the message to the target object
- read back the values as the attribute from [expose]
Would this work or would the idea for this special object qualify me for the special bus?
The reason why I really want to do this is because it allows me to write unit tests for max patches in JS. I'll follow up on that later if anyone's interested.
Thijs
You can grab the value of an object using:
this.patcher.getnamed("scripting_name").getvalueof();
when you know the scripting name of the object in question. However this isn't quite the same as what you're after. Especially for objects with multiple outlets like [function]. You can always script patchcords from the object's outlets back to your [js] inlet, and possibly some [prepend obj_name_outlet]s so you know where each message originated. The downside here is that with javascript you can't tell how many outlets some objects have when this is dependant on the arguments you instantiate it with. I even looked into a way of creating a [grab] object so the actual object you query doesn't send out the values itself.
Hopefully that is somewhat helpful.
lh
Most of these solutions crossed my mind, but I never tried just connecting the object outlet to my JS. The reason why I didn't expect it to work is because I need the value to arrive in my JS before I leave the function (unit test) which triggered the object output. I just tried it an it works!
myobject.message("getSomething")
// meanwhile the object output is routed to JS -> global_somevalues
var returnval = global_somevalues
Thanks for the tip on getvalueof(). I didn't know this. I guess it would be useful in combination with [zl reg] to hold the values. Now the JS input works I'll probably stick with that. It's not much of a difference anyway, both are a bit of a hack.
Thijs
I went for the getvalueof() approach eventually. I would just like to note that I tried [zl reg] first, but that didn't work because apparently it doesn't have a getvalueof() method. Reading about this method I was reminded that it has its roots in the pattr family. Now I use a [pattr] object to capture whatever I need from an objects output, and it works like a charm.
Thijs