multiple inlets problem

solconnection's icon

Hi guys, i am sure this is an easy problem but the tutorial and help file didn't have the information i needed to make this work or i completely missed something. I found another similar post in this forum here recently but the solutions posted didn't work for me unfortunately.

here is a pic of a simple patcher i have made to host the .js, it is loading it correctly
http://i651.photobucket.com/albums/uu233/solconnection/max-jstest.jpg
(ot: can you embed images on this forum?)

I have made a little test javascript file, and am sending two int's in to it, all i want to do is print the value of both ints from within the .js file, but the value of 'b' always comes out as

here is the contents of the .js file:
Code:

// test.js

// inlets and outlets
inlets = 2;
outlets = 2;

function list(a,b)
{
post(a,"-");
post(b,"n");
}

could anyone help? or point me in the direction of somewhere i can do some reading regarding more than one inlet (the tutorial only covers using one inlet)

thanks a million

solconnection's icon

also, just to pre-empt.

having researched this problem, i have seen a solution like this posted a few times
[code]// inlets and outlets
inlets = 2;
outlets = 2;

function list(a,b)
{
if (inlet == 1)
// right inlet
post(a,"-");
else
// left inlet
post(b,"n");
}
}
[/code]

which doesn't seem to work for me either :(
any ideas would be greatly appreciated :)

solconnection's icon

ok, i worked it out myself. this is the correct solution, note that the input function only supports one paramater, and you have to switch on the inlet value.

// inlets and outlets
inlets = 2;
outlets = 2;

function list(a)
{
if (inlet == 1)
{
// right inlet
post(a,"-");
}
else
{
// left inlet
post(a,"n");
}
}

Eddy's icon

You can supply a list to the inlet like this:

function list(inputList)
{
myJavascriptArray = arrayfromargs(arguments);
}

solconnection's icon

takk Eddy, much appreciated.

Michael Gary Dean's icon

This was a problem for me. I thought I'd share the solution I found.

This script is for js objects that need to take two lists as input and process them.

Hope that helps someone.

Mike

elanhickler's icon

alright, start over. here's a script that uses multiple inlets and outlets and it works!

//declare inlets and outlets
inlets = 4
outlets = 4
//initialize variables to some number so you don't get errors
var freq = 0;
var band = 0;
var window = 0;
var samplerate = 0;
//add the built in function of msg_float() so it does something when it receives a float
function msg_float(v)
{
//assign inlets with if statements
    if (inlet==0) freq = v
    if (inlet==1) band = v
    if (inlet==2) window = v
    if (inlet==3) samplerate = v    
//do some math    
    if (freqhiBin) loBin,hiBin = hiBin,loBin
    if (loFreq>hiFreq) loFreq,hiFreq = hiFreq,loFreq
//assign variables to outlets    
    outlet(0,loBin)
    outlet(1,hiBin)
    outlet(2,loFreq)
    outlet(3,hiFreq)
}

Nicklaus Rohrbach's icon

Thanks a lot guys !

jmejia@gmail.com's icon

this was a really helpful thread - not sure if multiple inlets is actually documented anywhere - thank you from the future!