Sending a message directly to object using JS
How can I send a message directly to an inlet of another object using javascript?
directly ?
by : messnamed()
https://cycling74.com/wiki/index.php?title=Javascript_in_Max_02_-_Global_Methods#messnamed_.28Max_object_name.2C_message_name.2C_any_arguments.29
another way is to specify JS name for an object and access it via : this.patcher.getnamed( "your varname" ).message( "built in message" , value )
Thanks for the reply but i still do not get it..
As an example I create a [sel 22] object and call it "sel1". I then want to send the message "22" to the inlet of "sel1" causing it to bang. Can I please ask you to advise how I can do this using both the messnamed() function and also this.pather.getnamed("sel1").message(....
Hi . sure .
this.patcher.getnamed("sel1").message('int',22);
u need to specify what type of message u want to send . in this case its an INT . as for the shorthand it could look like this
this.patcher.getnamed("sel1").int(22);
you can list all the methods of an max.object , so u will see what type of messages its expecting (for the further exploring).
var bangMe = function(){
var sel = this.patcher.getnamed("sel1")
listMethods(sel)
}
function listMethods(object){
var list = []
list = Object.getOwnPropertyNames(object)
.filter(function(property) {
return typeof object[property] == 'function';
}
);
post()
post("# METHODS #")
for(var i = 0 ; i < list.length ; i++){
post()
post(list[i]+"()")
}
post()
post("# END #")
}
###### EDIT #####
as for the list of properties
function listProps(obj){
for(var prop in obj){
post();
post(prop , " : " , obj[prop])
}
}
messnamed() actually refers to a Global objects . there is reference in JS Documentation .
also with sendnamed() you can communicate for example with [send] , [receive]
First I would like to thank you so much for the help so far and for the brilliant functions listMethods and listProps. I am almost about to accomplish what I set out to do but I have one final challenge. I have an object defined like this [udpsend 127.0.0.1 57120]. If send the message below to this object using a standard message box this works fine. The message I send is e.g "/oo nname set amp 1" . However I do not find a way of successfully sending the same message using javascript. When doing a listMethods on the udpsend I get the list below. Obviously the /oo is not a valid method. I have tried with ....anything("/oo nname set amp 1") etc but I do not get it to work. Is there some way I can send this message to [udpsend...]using javascript?
js: ################METHODS########################
js: bang()
js: int()
js: float()
js: list()
js: anything()
js: port()
js: host()
js: FullPacket()
js: maxqueuesize()
js: maxpacketsize()
js: sendbox()
js: ################END########################
Hi !! no worries :)
dont forget that there is a message() function around . so u can easily format it like this .
var udp = this.patcher.getnamed("yourUdpBox")
var bang = function(){
udp.message("/oo nname set amp 1")
}
EDIT : or
udp.anything("/oo"," nname"," set"," amp 1")
or
udp.list("/oo"," nname"," set"," amp 1")
EDIt 2 : this actually works fine
udp.anything("/oo nname set amp 1")
Thank you so much again for your advise. I finally get it to work now the way I want:)
This works for me
var udp = this.patcher.getnamed("nUdpsend1");
udp.message("/oo","nname","set","amp", 1);
(I did not get it to work with anything in this particular scenario but that is not important since the example above works)
Again thanks a million!!
great !
thats even better because commas lets you format the message in a dynamic way (you can "variablize" things between commas ,and im sure you will use it that way ),so definitely it will work much better for you , you are flexible now .
have a lot of fun !
EDIT :
but its strange that anything() wont let you do this .