Forums > MaxMSP

accessing multiple inlets from js object

November 28, 2006 | 8:57 pm

sorry if i missed somehting completely obvious but i need to assign each input on my js object to a different variable in the javascript file. so far any input i use changes on the "throttle" variable and the inlet() function gives an error that it does not exitist, any help would be incredibaly apreciated.

follows are the patcher and javascript

———————————-
max v2;
#N vpatcher 263 138 863 538;
#P window setfont "Sans Serif" 9.;
#P number 179 109 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 148 275 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 224 284 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 60 259 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P slider 103 60 15 101 0 1;
#P objectname x;
#P window linecount 1;
#P newex 104 214 131 9109513 js 3 10;
#P objectname Acceleration;
#P connect 0 0 2 0;
#P connect 1 0 0 0;
#P connect 0 1 4 0;
#P connect 5 0 0 7;
#P connect 0 2 3 0;
#P pop;

——————————–

var throttle = 0;
var cutoff = 6500;
var rpm = 1000;
var ratio = 3.45;
var fd = 3.94;
var load = 0;
var speed = 0;
var dragco = 0.31;
var drag = 0;
var tire_w = 195;
var tire_s = 45;
var rim = 15;
var pi = 3.14159;
var acc = 0;

function msg_int(throttle)
{
speed_cal(tire_w,tire_s,rim,fd,ratio,rpm);
drag_co(dragco);
acceleration();
outlet (0, throttle);
}

function speed_cal(tire_w,tire_s,rim,fd,ratio,rpm)
{
speed=(tire_s*tire_w/100+rim*25.4/2)*2*pi*rpm*60/(fd*ratio*1000000);
outlet (1, speed);
}

function drag_co(dragco)
{
drag = speed * dragco;
// outlet (0, drag);
}

function acceleration()
{
acc = power() – drag;
// outlet (0, acc);
}

function power()
{
if(rpm < cutoff)
load = Math.sqrt(rpm) * throttle;
else
load = Math.sqrt(rpm);
outlet (2, load);
}


November 29, 2006 | 7:35 am

inlets can be accessed as a property of the jsthis object, see the
JavascriptInMax.pdf page 14.

in the script you access it like so:

if(this.inlet == 0) for the leftmost inlet

or with a switch statement for a more elegant routing structure

switch(this.inlet){
case 0:
case 1:
etc.
}

hth

/*j

> sorry if i missed somehting completely obvious but i need to assign
> each input on my js object to a different variable in the
> javascript file. so far any input i use changes on the "throttle"
> variable and the inlet() function gives an error that it does not
> exitist, any help would be incredibaly apreciated.


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