View Single Post
Old 12-13-2011, 12:14 PM   #4
Erriez
Mortal
 
Join Date: Jun 2010
Location: The Netherlands
Posts: 104
Default

I saw the other thread, but I had a different question: I'd like to define multiple normal arrays mixed with multidimension arrays. After spending a lot of time to reinvent the wheel about this undocumented stuff, I found a solution.

My problem was located in the definition of the arrays which is completely different than I expected. Please find below a full working example with a memory verification:

Code:
errorsArray1 = 0;
errorsArray2 = 0;
errorsArray3 = 0;

// C style: int array1[3];
array1 = 3;
// C style: int array2[2][3];
array2 = (array1 + (2*3));
// C style: int array3[4];
array3 = (array1 + array2 + 4);

// Initialize arrays
array1[0] = 11;
array1[1] = 12;
array1[2] = 13;

array2[(0*3)+0] = 14;
array2[(0*3)+1] = 15;
array2[(0*3)+2] = 16;
array2[(1*3)+0] = 17;
array2[(1*3)+1] = 18;
array2[(1*3)+2] = 19;

array3[0] = 20;
array3[1] = 21;
array3[2] = 22;
array3[3] = 23;

// Verify arrays
(array1[0] != 11) ? errorsArray1 += 1;
(array1[1] != 12) ? errorsArray1 += 1;
(array1[2] != 13) ? errorsArray1 += 1;

(array2[(0*3)+0] != 14) ? errorsArray2 += 1;
(array2[(0*3)+1] != 15) ? errorsArray2 += 1;
(array2[(0*3)+2] != 16) ? errorsArray2 += 1;
(array2[(1*3)+0] != 17) ? errorsArray2 += 1;
(array2[(1*3)+1] != 18) ? errorsArray2 += 1;
(array2[(1*3)+2] != 19) ? errorsArray2 += 1;

(array3[0] != 20) ? errorsArray3 += 1;
(array3[1] != 21) ? errorsArray3 += 1;
(array3[2] != 22) ? errorsArray3 += 1;
(array3[3] != 23) ? errorsArray3 += 1;
Output: Variables errorsArray1, errorsArray2 and errorsArray3 are 0 which is OK.

Can someone please update the outdated page below?
http://www.reaper.fm/sdk/js/js.php
Arrays are the basics of programming! (Sorry for my frustration about this)

Thanks for your help!

Last edited by Erriez; 12-13-2011 at 12:55 PM.
Erriez is offline   Reply With Quote