array of arrays

BlitzMax Forums/BlitzMax Beginners Area/array of arrays

dmaz(Posted 2004) [#1]
I saw mention of
New array of arrays (of arrays etc...).
in versions.txt but couldn't find any docs on it.

it doesn't look like you can do an auto array of array ie:
local a[] = [[1,2],[3,4,5],[1,2]]

How is it used?


Todd(Posted 2004) [#2]
I couldn't get your example to work, but if you use the 'Array' type it works. There's a catch though: All the elements and subelements have to be the same type. Example:

Foo:Array = [[1, 2, 3], [1, 2, 3]] 'OK!
Foo:Array = [["A", "B", "C"], [1, 2, 3]] 'Not OK



Michael Reitzenstein(Posted 2004) [#3]
It's an array of an array, so the syntax would be:

Local a[][] = [ [1,2], [3,4,5], [1,2] ]


dmaz(Posted 2004) [#4]
if that's the case, how are the inner arrays accessed?


marksibly(Posted 2004) [#5]
By indexing the outer array!


Local a[][]=[[1],[2,3],[4,5,6]]

For Local a1[]=EachIn a
For Local a2=EachIn a1
Print a2
Next
Next



a[][] is an array of arrays.

a1[] is each array in a[][]

a2 is each int in a1[]

You can also use standard BASIC multidimensional arrays, but the [exp,exp...] syntax only works with 1 dimsenional arrays. And yes, an array of arrays is a one dimensional array.


Michael Reitzenstein(Posted 2004) [#6]
a[ 0 ] = [ 1, 2 ]
a[ 1 ] = [ 3, 4, 5 ]
a[ 2 ] = [ 1, 2 ]

Therefore

a[ 0 ][ 0 ] = 1

Etc.


dmaz(Posted 2004) [#7]
couldn't figure out the syntax... I didn't think of putting the brackets in the first "For" loop. makes sense though. Great addition to Blitz!