get data from a multislider into javascript?
Hey folks,
So what I want to do is tie a multislider to one of my javascript functions to control dynamic animation.
My first attempt was to grab the data out of the left outlet and input it into my js function using prepend. The trouble is, doing it this way it treats each number in the multi as a separate variable. That'd be fine except I want to be doing complex waveforms requiring at least 50 sliders - that's a long argument list to call in the function, and also I'd like the number of sliders to vary so the function needs to be operable for any number of variables.
So the best thing I can think of is to somehow combine all the values into a string or an array of values. However my Max-fu isn't strong enough to figure out how to do this.
Can you provide any solutions? Or alternate ways to send data from a multislider to JS?
Thanks!
probably not the best, but maybe a start?
//---------------------------------//
autowatch = 1;
test = new Array();
prev = -1;
function list() {
if (arguments.length) {
nargs = arguments.length;
if (prev > nargs) {
test.length = 0;
post ("nargs =",nargs,"n");
}
prev = nargs;
for (i = 0; i
test[i] = arguments[i];
}
outlet(0, test);
}
}
//---------------------------------//
that looks promising - here's a total noob question though - how do I turn the code you sent me back into a patcher?
copy and past everything between (and including) ----------begin_max5_patcher---------- and -----------end_max5_patcher-----------. past it into an empty max window.
Then copy the javascript code. open the js object in the max code, paste it there and save.
Brilliant! Thanks for your help MIB, that's just what I needed.
It looks like there's something wrong with the for statement, and there are also some syntax issues.
Could you provide corrected JS ?
autowatch = 1;
test = new Array();
prev = -1;
function list() {
if (arguments.length) {
nargs = arguments.length;
if (prev > nargs) {
test.length = 0;
post (“nargs =”,nargs,”n”);
}
prev = nargs;
for (i = 0; i < nargs ; i++){
test[i] = arguments[i];
}
outlet(0, test);
}
}
Thanks Krisw. :-)