Forums > Javascript

get data from a multislider into javascript?

February 1, 2011 | 4:53 am

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!



MIB
February 1, 2011 | 5:48 am

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

February 1, 2011 | 6:39 am

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



MIB
February 1, 2011 | 5:54 pm

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.


February 4, 2011 | 4:57 am

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


June 18, 2013 | 10:50 am

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

Could you provide corrected JS ?


June 28, 2013 | 7:06 am
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);
	}
}

July 18, 2013 | 11:55 am

Thanks Krisw. :-)


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