get data from a multislider into javascript?

Feb 1, 2011 at 4:53am

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!

#54707
Feb 1, 2011 at 5:48am

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);
}
}
//———————————//


----------begin_max5_patcher----------
434.3oc0U9sSCBCEF+Z3onowKYDZEXLuy2AuyrXJPcqKPYgVhSW16tzVX+QY
JClKwaJiuyIse+NmSYassfwEanBH3Avy.Kqs1VVZIkfUy6VvbxljLhPmFLmJ
DjETniIljtQp0m34F3iiBlB1+q1bXo5LJhWMAgZEesfK4jbpNzikLRVaj0DY
xRFewKkzDowZ9gSc8b.gH0ZPPj5AJz0CL+ncSv9PuaHu5vFYdUNimQkZqiOH
VTIaUQMpFI46qoliDBAyUQ1YaqVb5a4oJSxDYrTZYG3O6GXDi0zgMzgQFHwd
GQ4I3zZ7Vr6FO7YwyYnHVe.wcRW3f5sXjut2h08VOM0QWXqEcYry3RE9wD9h
A1kOyk.kOA2g5n13OlZSjd0G+ecrG+6Hh7Ly6A2qdLEeoS8I0UhThjLfogQb
Sf9VMdeaJXk.japEOQER2Uht9P3XlGvd5qIQnq3kkdNPnOIXFi+0+0P6Vk9o
0KQQUYR6V0.N3feSqKPLNQxJ3GmiJIz9jVxRSo53s7jyRWWTeKtwCmo4cMsz
rSx4u1Qg8vQ92TG42CGguoNB2mAoQ3n5W1Y+I3mMUnD
-----------end_max5_patcher-----------
#197039
Feb 1, 2011 at 6:39am

that looks promising – here’s a total noob question though – how do I turn the code you sent me back into a patcher?

#197040
Feb 1, 2011 at 5:54pm

copy and past everything between (and including)

– Pasted Max Patch, click to expand. –

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

#197041
Feb 4, 2011 at 4:57am

Brilliant! Thanks for your help MIB, that’s just what I needed.

#197042
Jun 18, 2013 at 10:50am

It looks like there’s something wrong with the for statement, and there are also some syntax issues.

Could you provide corrected JS ?

#253121
Jun 28, 2013 at 7:06am
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);
	}
}
#254382
Jul 18, 2013 at 11:55am

Thanks Krisw. :-)

#256393

You must be logged in to reply to this topic.