Forums > Javascript

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<65; i++) {
so[i] = new Array();

for (j=0 ; j<41; j++) {
so[i][j] = i ;
} }

function getvalueof (a)
{
return so;
}
//———————————————-//
// end of the js script //
//———————————————-//

max patch :

max v2;
#N vpatcher 194 116 1464 771;
#P window setfont "Sans Serif" 12.;
#P newex 48 250 32 9109516 print;
#P message 48 154 46 9109516 getseq;
#P newex 147 193 56 9109516 autopattr;
#X prestore seq 130 0 jsobject 25706288 jsobject 25706296 jsobject 25706304 jsobject 25706312 jsobject 25706320 jsobject 25706328 jsobject 25706336 jsobject 25706344 jsobject 25706352 jsobject 25706360 jsobject 25706368 jsobject 25706376 jsobject 25706384 jsobject 25706392 jsobject 25706400 jsobject 25706408 jsobject 25706416 jsobject 25706424 jsobject 25706432 jsobject 25706440;
#X prestore seq 130 40 jsobject 25706448 jsobject 25706456 jsobject 25706464 jsobject 25706472 jsobject 25706480 jsobject 25706488 jsobject 25706504 jsobject 25706512 jsobject 25706520 jsobject 25706528 jsobject 25706536 jsobject 25707464 jsobject 25707472 jsobject 25707480 jsobject 25707488 jsobject 25707496 jsobject 25707504 jsobject 25707512 jsobject 25707528 jsobject 25707536;
#X prestore seq 130 80 jsobject 25707544 jsobject 25707552 jsobject 25707560 jsobject 25707568 jsobject 25707576 jsobject 25707592 jsobject 25707600 jsobject 25707608 jsobject 25707616 jsobject 25707624 jsobject 25707632 jsobject 25707640 jsobject 25707648 jsobject 25707664 jsobject 25708016 jsobject 25708024 jsobject 25708032 jsobject 25708040 jsobject 25708048 jsobject 25708056;
#X prestore seq 130 120 jsobject 25708064 jsobject 25708072 jsobject 25708080 jsobject 25708088 jsobject 25708096;
#P objectname u445000019;
#P newex 147 228 88 9109516 js test_array.js;
#P objectname seq;
#P newex 48 222 74 9109516 pattrstorage;
#X client_rect 99 283 1151 607;
#X storage_rect 0 0 640 240;
#P objectname u122000018;
#P comment 101 155 141 9109516 click for print array;
#P connect 4 0 1 0;
#P connect 1 0 5 0;
#P connect 3 0 2 0;
#P pop;


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.


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