trouble accessing value of 2nd inlet in js object :(

Questions and discussion about building and using Max for Live devices
Post Reply
solconnection
Posts: 76
Joined: Fri Aug 24, 2007 4:14 am

trouble accessing value of 2nd inlet in js object :(

Post by solconnection » Fri Dec 18, 2009 4:07 pm

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 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 <undefined>

Image

Code: Select all


// 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
Posts: 76
Joined: Fri Aug 24, 2007 4:14 am

Re: trouble accessing value of 2nd inlet in js object :(

Post by solconnection » Fri Dec 18, 2009 7:45 pm

also, just to pre-empt.

having researched this problem, i have seen a solution like this posted

Code: Select all

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

function list(a,b)
{
    if (inlet == 1)
       // right inlet
        post(a,"-");
     else
    // left inlet
       post(b,"\n");
    }
}
which doesn't seem to work for me either :(
any ideas would be greatly appreciated :)

steff3
Posts: 330
Joined: Sat Jul 10, 2004 10:16 am

Re: trouble accessing value of 2nd inlet in js object :(

Post by steff3 » Fri Dec 18, 2009 8:18 pm

hmm, the list(a, b) seems strange ...

function msg_int(val) {
if (inlet == 1) {
post ("right ", val);
} else {
post ("left ", val);
}

}

Do not know if that functions - in front of my Internet computer ...

With list - list begin with digits ...

so you could also try

function list(a) {
if (inlet == 1) {
post ("right ", arguments[0]);
} else {
post ("left ",arguments[0]);
}


Not really sure if that works - just a theoretic try ...

maybe that helps

best
}
Last edited by steff3 on Fri Dec 18, 2009 8:24 pm, edited 1 time in total.

solconnection
Posts: 76
Joined: Fri Aug 24, 2007 4:14 am

Re: trouble accessing value of 2nd inlet in js object :(

Post by solconnection » Fri Dec 18, 2009 8:20 pm

thanks mate :) i just figured this out myself too...

it doesn't work with multipla params (a,b)...your soloution seems on the money.

i just got this little bit of code to work, so ill paste it incase anyone else has issues.

Code: Select all

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");
    }
}
thanks for your help, have a nice day

amounra93
Posts: 431
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: trouble accessing value of 2nd inlet in js object :(

Post by amounra93 » Fri Dec 18, 2009 9:59 pm

Try something like this:

Code: Select all

function list(args){
    if(inlet==1){
        outlet(0,"in 1", args[1]);}
    if(inlet==2){
        outlet(0,"in 2", args[1]);}}
If you cast the arguments to list as an array, I think you can get the result you want.

Its definitely possible to have multiple arguments.
http://www.aumhaa.com for Monomod and other m4l goodies.

Post Reply