Sending messages using javascript


    Jun 02 2008 | 10:45 pm
    Hey all, I am trying to insert data into a coll via
    js but have not been able to get it right. Can some
    one take a quick look at this and help me figure out
    what I am doing wrong.
    Thanks,
    Anthony
    testmess.js----------------------
    function test()
    {
    post("testn");
    //messnamed ("testcoll", "1 somedata"); // //return;
    var p = this.patcher;
    var mobj = p.getnamed ("testcoll");
    if(mobj == null)
    post("mobj not foundn");
    else
    mobj.message("anything", "1 somedata");
    }

    • Jun 02 2008 | 11:01 pm
      On 3 juin 08, at 00:45, Anthony Palomba wrote:
      >
      > Hey all, I am trying to insert data into a coll via
      > js but have not been able to get it right. Can some
      > one take a quick look at this and help me figure out
      > what I am doing wrong.
      > mobj.message("anything", "1 somedata");
      Should be:
      mobj.message(1, "somedata");
      because coll expect a list with the first argument which should be an
      int followed by any number of argument (separated by comas in your js,
      unless you provide an Array).
      HTH,
      ej
    • Jun 03 2008 | 3:30 pm
      I see, that is really confusing...
      One other thing, why does the following statement not work...
      messnamed ("testcoll", 1, "somedata");
      Thanks,
      Anthony
    • Jun 03 2008 | 3:47 pm
      On 3 juin 08, at 17:30, Anthony Palomba wrote:
      > I see, that is really confusing...
      >
      > One other thing, why does the following statement not work...
      >
      > messnamed ("testcoll", 1, "somedata");
      Well it does work, but not the way you probably expect ;-) It send the
      list [1 somedata] to a receive called testcoll.
      ej
    • Jun 03 2008 | 6:56 pm
      Ahhh, I see. I thought you could use messnamed
      for any named object. Good to know, thanks.
    • Jun 03 2008 | 7:30 pm
      Just so that I am sure, are send/rcv objects the only things
      I can use messnamed for?
    • Jun 03 2008 | 8:48 pm
      no, it works for all named objects...
      your example works, but you have to respect what the coll object
      understands.
      the anything message doesn't trigger any storage action.
      use the "store" message to store a 'list' that begins with a symbol
      (an "anything" type), otherwise send a 'legal' list, where the first
      element is the key.
      hth
      /*j
      /*
      save as testmess.js
      */
      var mobj = this.patcher.getnamed ("testcoll");
      var mobj2 = this.patcher.getnamed ("mytext");
      function test()
      {
      if(mobj == null) {
      post("mobj not found");
      } else {
      mobj.message(3, "yet_other_data");
      mobj.message("store", "C", "yet_some_more_data");
      }
      }
      function mess()
      {
      var a = arrayfromargs(arguments);
      if(mobj == null) {
      post("mobj not found");
      } else {
      post("sending "+a+"n");
      mobj.message(a);
      }
      }
      function read()
      {
      if(mobj2 == null) {
      post("mobj not found");
      } else {
      mobj2.message("read", "readme.rtf");
      }
      }
      // EOF
    • Jun 03 2008 | 9:23 pm
      On 3 juin 08, at 22:48, jasch wrote:
      > no, it works for all named objects...
      just to make it clear, messnamed() only send messages to receives
      objects. For any object you can use the message() method for a MaxObj
      as Jan showed.
      ej