Getting object value using the Java API
How can one GET the value of a given MaxBox?
Using the Java API it's possible to SET the value of an object's value and attributes using this method:
MaxPatcher p = this.getParentPatcher();
MaxBox mb = p.getNamedBox("objectScriptNameHere");
mb.send( 12 );
This is listed within the Java API documentation in the /java-doc/api folder structure of the Max installation. However, I'm unable to find the GET method.
No dice? Jan?
There is a fairly long and winding way around this, by creating and deleting some objects and so on...
public void bang() {
MaxPatcher thePatcher = this.getParentPatcher();
MaxBox self = this.getMaxBox();
MaxBox numberBox = thePatcher.getNamedBox("number"); //Assumes existing object named "number"
MaxBox grab = this.getParentPatcher().newDefault(50, 50, "grab", null);
MaxBox prepender = this.getParentPatcher().newDefault(50, 80, "prepend", Atom.parse("number"));
thePatcher.connect(grab, 1, numberBox, 0); //connect grab object to number object
thePatcher.connect(grab, 0, prepender, 0); //connect grab object to prepend object
thePatcher.connect(prepender, 0, self, 0); //connect prepend object to mxj object
numberBox.send(42);
grab.bang(); //trigger the grab object
grab.remove(); //Remove the temporary objects
prepender.remove();
}
public void number(int x) {
post("The number is " + x);
}
This bit of code was inspired by this topic:
https://cycling74.com/forums/getting-the-integer-value-of-a-number-object/