Forums > Javascript

distinguishing between inlets

May 19, 2008 | 12:04 pm

Hi,

inlets = 2;
outlets = 2;

function msg_int(a){ // receives value from inlet 0
outlet(0, 100-a); // sends value to outlet 0
outlet(1, a); // sends value to outlet 1
}

How can I read the value from inlet 1? With such wisdom, I’ll be able to take over the world!! Currently helpless.

Thanks very much,


May 19, 2008 | 12:29 pm

The reason the manual isn’t helping me is because it states inlet(no, get) yet inlet is not a function

Docs also imply using msg_int(a, b, c..) and this happens:

function msg_int(a, b){
post(a); // will output a or b
post(b); // nothing
}


May 19, 2008 | 12:45 pm

I think Emmanuel already answered this few days ago…
Ciao

// ———————————————–
inlets = 2;

function msg_int(v)
{
if (inlet == 1) {
post();
post(v, "in right inlet");
}
else {
post();
post(v, "in left inlet");
}
}
// ———————————————–


May 19, 2008 | 12:47 pm

On 19 mai 08, at 14:29, Glen wrote:

>
> The reason the manual isn’t helping me is because it states
> [b]inlet(no, get)[/b] yet inlet is not a function
>
> it also [i]implies[/i] using msg_int(a, b, c..) and this happens:
>
> function msg_int(a, b){
> post(a); // will output a or b
> post(b); // nothing
> }

if you send a list to your js object you need to use a list function

function list(a, b)
{
post(a); // first list item
post(b); // second list item
}

To know from which inlet a message arrived in your js, you need to
look at the inlet property (a variable). So:

inlets = 2; // define the number of outlets of your js object

function msg_int(v)
{
if (inlet == 1) // second inlet
post(v, " was received in the second inletn");
else
post(v, "was received in the left inletn");
}

HTH,
ej


May 19, 2008 | 4:30 pm

Thanks guys! :)

Its too late for my exam, but I’ll remember it for the future.


May 22, 2008 | 8:40 pm

personally i’m fond of case statements, there’s less temptation to mix in other logic with an "if" that picks your inlet:

function list() {
switch(inlet) {
case 0:
// do stuff;
break;
case 1:
// do stuff;
break;
}
}


Viewing 6 posts - 1 through 6 (of 6 total)