Sending messages using javascript

Jun 2, 2008 at 10:45pm

Sending messages using javascript

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

– Pasted Max Patch, click to expand. –

testmess.js———————-

function test()
{
post(“testn”);

//messnamed (“testcoll”, “1 somedata”); //

#38215
Jun 2, 2008 at 11:01pm

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

#132919
Jun 3, 2008 at 3:30pm

I see, that is really confusing…

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

messnamed (“testcoll”, 1, “somedata”);

Thanks,
Anthony

#132920
Jun 3, 2008 at 3:47pm

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

#132921
Jun 3, 2008 at 6:56pm

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

#132922
Jun 3, 2008 at 7:30pm

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

#132923
Jun 3, 2008 at 8:48pm

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

– Pasted Max Patch, click to expand. –

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

#132924
Jun 3, 2008 at 9:23pm

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

#132925

You must be logged in to reply to this topic.