How to retreive data from max send objects (aka receive inside JS)recev

Feb 2, 2009 at 7:22pm

How to retreive data from max send objects (aka receive inside JS)recev

Hello,

I’m fine with sending data from JS to max land (using messnamed) but how to do the other way around ?
How to receive inside JS data that are sent from my max patch through ‘send’ object ?

Thanks for any help,

Salvator

#42062
Feb 17, 2009 at 8:23am

Anyone ?

Salvator

#150280
Feb 17, 2009 at 11:13am

It could be done by writing a javascript that uses global functions. You could replace your [send]s with a js that stores a global that you can use in your other js and that also uses the messnamed thing to act as a regular [send]. I’m about to head to work but if you want I’ll put something together this evening and post it here.

lh

#150281
Aug 31, 2011 at 11:19pm

It’s been a while since this post, but I’m curious: how do you declare global functions in js? could you post a simple example of how to communicate two javascripts?
thanks in advance!

#150282
Sep 1, 2011 at 1:32am

Hi
Try sticking a js object in a patch and get help on it . . ..
It will tell you “For more info about the js object, pease consult the Javascript in Max documentation, and the various examples located in ./examples/javascript. “
In these you will find what you need to know, there is even a globalvar example patch . . .
Cheers
MM

#150283
Sep 1, 2011 at 9:14am

Here’s some code that will work like a simple version of the [value] object, the only difference being that you don’t set a name for the object, every instance will be linked.

glob = new Global("uniquename");

function anything() {
    glob.tosend = arrayfromargs(messagename, arguments);
}

function bang() {
    outlet(0,glob.tosend);
}
#150284
Sep 1, 2011 at 4:57pm

Umm… how about hooking up a [receive] object to one of your [js] inlets?

It has the advantage that you can double-click on the [send] and the recipient will be in the popup menu. Big help for debugging.

#150285
Sep 1, 2011 at 7:43pm

Thanks for the answers
@Macciza I did know a little bit about the global variables, but I thought that they were “variables”, not functions, that´s the reason why I asked. But surely I missed something in the documentation, I’m quite new with js and scripting in general.

I’ll check out Luke’s example

– Pasted Max Patch, click to expand. –

//js file code.js

inlets =1;
outlets=1;

function printHello() {
outlet(0, “hello”);

}

//end js file

#150286
Oct 1, 2011 at 3:04pm

BTW: in javascript, you can assign a variable to contain a function. This is occasionally useful when, for instance, you want to determine which function you want to use on the fly. see http://stackoverflow.com/questions/4908378/javascript-array-of-functions for example.

#150287

You must be logged in to reply to this topic.