Sending a message directly to object using JS


    Nov 11 2013 | 4:27 pm
    How can I send a message directly to an inlet of another object using javascript?

    • Nov 11 2013 | 5:26 pm
      another way is to specify JS name for an object and access it via : this.patcher.getnamed( "your varname" ).message( "built in message" , value )
    • Nov 11 2013 | 8:28 pm
      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(....
    • Nov 11 2013 | 10:33 pm
      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])	
      	}
      
      }
      
      
      
    • Nov 11 2013 | 10:44 pm
      messnamed() actually refers to a Global objects . there is reference in JS Documentation . also with sendnamed() you can communicate for example with [send] , [receive]
    • Nov 12 2013 | 9:57 pm
      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########################
    • Nov 13 2013 | 10:37 am
      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")
      
      
    • Nov 13 2013 | 1:32 pm
      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!!
    • Nov 13 2013 | 1:41 pm
      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 .