Here is an example of each type of array. In the first example we have a Matrix [x,y] type array. these arrays are like excel spreadsheets or a piece of graphpaper. these cannot be sliced. they have an advantage in that they are easier to set up and more intuitive (for me at least) to use:
[X,Y]
0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
This is an Array of Arrays [X][Y]. these offer much more flexibility. (can be sliced, can be resized) but require more setup and are less intuitive. Check out the output for Element Map[3] after the resize:
[X] [....Y.....]
[0] [0,1,2,3,4]
[1] [0,1,2,3,4]
[2] [0,1,2,3,4]
[3] [0,1,2,3,4,5,6,7,8,9...]
[4] [0,1,2,3,4]
So the Biggest advantage of 'Array of Arrays' is that they can be resized, sliced, diced etc. you can start off with an emty array[][] and resize it from within your program.
[X,Y]
0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
SuperStrict Local xcells:Int = 10 Local ycells:Int = 10 Local map:Int[xcells,ycells] Print Len(map) For Local CX:Int = 0 To xcells-1 For Local CY:Int = 0 To ycells-1 map[CX,CY] = CY Next Next Print "created" +xcells*ycells For Local CX:Int = 0 To xcells-1 Print "Map["+CX+"]" For Local CY:Int = 0 To ycells-1 Print " Map["+CX+","+CY+"]="+map[CX,CY] ' "CX:"+CX+" CY:"+CY Next Next
This is an Array of Arrays [X][Y]. these offer much more flexibility. (can be sliced, can be resized) but require more setup and are less intuitive. Check out the output for Element Map[3] after the resize:
[X] [....Y.....]
[0] [0,1,2,3,4]
[1] [0,1,2,3,4]
[2] [0,1,2,3,4]
[3] [0,1,2,3,4,5,6,7,8,9...]
[4] [0,1,2,3,4]
SuperStrict Local xcells:Int = 5 Local ycells:Int = 5 Local map:Int[][] map = map[..xcells] For Local this_cell:Int = 0 To xcells - 1 map[this_cell] = map[this_cell][..ycells] Next map = map[..xcells][..ycells] Print Len(map) For Local CX:Int = 0 To xcells-1 For Local CY:Int = 0 To ycells-1 map[CX][CY] = CY Next Next Print "created" +xcells*ycells For Local CX:Int = 0 To xcells-1 Print "Map["+CX+"]" For Local CY:Int = 0 To Len(map[CX])-1 Print " Map["+CX+"]["+CY+"]="+map[CX][CY] ' "CX:"+CX+" CY:"+CY Next Next Print "*************** Resize of Map[3] to 25 elements ( Map[3][..25] ) **************" ' you can resize at any time. map[3] = map[3][..25] For Local CX:Int = 0 To xcells-1 Print "Map["+CX+"]" For Local CY:Int = 0 To Len(map[CX])-1 Print " Map["+CX+"]["+CY+"]="+map[CX][CY] ' "CX:"+CX+" CY:"+CY Next Next
So the Biggest advantage of 'Array of Arrays' is that they can be resized, sliced, diced etc. you can start off with an emty array[][] and resize it from within your program.