get data from a multislider into javascript?


    Feb 01 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!

    • Feb 01 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); } } //---------------------------------//
    • Feb 01 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?
    • Feb 01 2011 | 5:54 pm
      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.
    • Feb 04 2011 | 4:57 am
      Brilliant! Thanks for your help MIB, that's just what I needed.
    • Jun 18 2013 | 5:50 pm
      It looks like there's something wrong with the for statement, and there are also some syntax issues.
      Could you provide corrected JS ?
    • Jun 28 2013 | 2:06 pm
      
      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);
      	}
      }
      
      
      
    • Jul 18 2013 | 6:55 pm
      Thanks Krisw. :-)