3+ Dimensional Arrays

How to Make 3+ Dimensional Arrays
Many people are under the misconception that it is impossible to have an array of more than two dimensions on PTC for DSi. This is not completely true. The interpreter does not allow one to define a three dimensional array directly with the DIM instruction, but with a little creativity a one or two dimensional array can be turned implicitly into an array of almost any number of dimensions.

To start we will make a two dimensional array ARRAY2D(X,Y) using a one-dimensional array. It is quite simple here is the code:

DIM ARRAY2D(X*Y)

That is all! In order to find value (4,2) in that array you can substitute ARRAY3D(4+2X) where X is the number of values in the X dimension of the entire array. This works because a two dimensional array can be thought of as a one dimensional array divided into segments. The Y dimension represents which segment you are choosing and the X dimension represents which value in that segment you are choosing. The length of each segment is equal to the X value used in DIM. Because of this by multiplying the Y value you want by the number of x-values (the length of each segment) and adding the X value you want you get the equivalent to (X,Y) in a one dimensional array.

This can be applied to a three dimensional array too using the code:

DIM ARRAY3D(X*Y*Z)

The value for (2,3,5) is then retrieved with ARRAY3D(2+3*X+5*Y). Once again think of segments only this time the array is divided into Z segments made of the Y segments discussed earlier. You can keep on adding dimensions from here until you start hitting the limit for the number of values in a PTC array.

Credits
alfanzothehutt