SAVE THE CONTENT OF A ENTIRE ARRAY IN JS OBJECT


    May 31 2006 | 9:03 am
    Hi list,
    I tried to make a js object containning a two dimensional array with 64 row containning 40 int for each (so 2560 value = compatible with pattr).
    I would like to save the content of an entire array with the "getvalueof" method. My problem is that for the moment I just can save one row of this array.
    my name array is so
    if I write:
    function getvalueof (a)
    {
    return so;
    }
    max return in pattr some error values
    if I write:
    function getvalueof (a)
    {
    return so[1];
    }
    max return in pattr value of the second row of my array (and it's normal)
    but I would like save all the row of my array.
    cheers, Nico.
    js content :
    //--------------------------------------------//
    // save @ test_array.js //
    //--------------------------------------------//
    editfontsize=14;
    so = new Array(4);
    for (i=0 ; i so[i] = new Array();
    for (j=0 ; j so[i][j] = i ;
    } }
    function getvalueof (a)
    {
    return so;
    }
    //----------------------------------------------//
    // end of the js script //
    //----------------------------------------------//
    max patch :
    max v2;

    • May 31 2006 | 11:13 am
      you have to turn your 2D array into a 1D array to store it in pattr. Then you can convert it back to a 2D array in your setvalueof() function (see below).
      oli
      //test_array.js
      autowatch = 1;
      so = new Array();
      for (i = 0; i < 65; i++)
      {
      so[i] = new Array();
      for (j = 0; j < 41; j++)
      {
      so[i][j] = j;
      }
      }
      function setvalueof()
      {
      so = new Array();
      for (i = 0; i < 65; i++)
      {
      so[i] = new Array();
      for (j = 0; j < 41; j++)
      {
      so[i][j] = arguments[a++];
      }
      }
      }
      function getvalueof()
      {
      var data = new Array();
      var dataIdx = 0;
      for (i = 0; i < 65; i++)
      {
      for (j = 0; j < 41; j++)
      {
      data[dataIdx++] = so[i][j];
      }
      }
      return data;
      }
      //end
    • May 31 2006 | 1:51 pm
      Thanx oli, it works fine.
      best regards, nico.