Sending messages using javascript

Anthony Palomba's icon

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

Max Patch
Copy patch and select New From Clipboard in Max.

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");

}

Emmanuel Jourdan's icon

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

Anthony Palomba's icon

I see, that is really confusing...

One other thing, why does the following statement not work...

messnamed ("testcoll", 1, "somedata");

Thanks,
Anthony

Emmanuel Jourdan's icon

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

Anthony Palomba's icon

Ahhh, I see. I thought you could use messnamed
for any named object. Good to know, thanks.

Anthony Palomba's icon

Just so that I am sure, are send/rcv objects the only things
I can use messnamed for?

jasch's icon

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

Max Patch
Copy patch and select New From Clipboard in Max.

/*
    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

Emmanuel Jourdan's icon

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