Please try this code:
It crashes on c[0][0]=20 with "attempt to index array element beyond length" when you have debug mode on.
Note how with a single array you can grow it (with slicing) and also how the length of a single element is 1. Oh yeah why is Len(a) 5 and not 6 because 0..5 = 6 elements! (oh wait, I remember, slicing is 1 based and zero means null right?)
With a standard 2 dimensional array, you can't slice it (shame). Len returns the full size and a single element is 1.
Now here's the weird one...I was trying to use a double array so that I could grow each part. Note how the Len(c) returns 10, the number of elements in the second part. What's odd is that Len(c[0]) returns 0 because the element is null yet Len(c[0][0]) returns 1 because the element has a length of 1. Then it fails to set c[0][0] because it thinks it's out of bounds. So basically the double slice has failed on the first index, but seems OK on the second index (I think).
Maybe I'm trying to use the compiler on a way it's not designed, but I'd really like to have a 2D array that I can grow and shrink (think tile-based level that you may want to alter whenever it's loaded).
Strict Print "-----" 'single Local a[] Print Len(a) a = a[0..5] Print Len(a) Print Len(a[0]) a[0]=20 Print a[0] Print "-----" 'double 1 Local b[2,2] Print Len(b) 'b = b[0..5,0..10] (can't use slices with double arrays) :-( 'Print Len(b[0]) 'incorrect number of dimensions, yep fair enough Print Len(b[0,0]) b[0,0]=20 Print b[0,0] Print "-----" 'double 2 Local c[][] Print Len(c) c = c[0..5][0..10] Print Len(c) Print Len(c[0]) Print Len(c[0][0]) c[0][0]=20 'fails here Print c[0][0] Print "-----"
It crashes on c[0][0]=20 with "attempt to index array element beyond length" when you have debug mode on.
Note how with a single array you can grow it (with slicing) and also how the length of a single element is 1. Oh yeah why is Len(a) 5 and not 6 because 0..5 = 6 elements! (oh wait, I remember, slicing is 1 based and zero means null right?)
With a standard 2 dimensional array, you can't slice it (shame). Len returns the full size and a single element is 1.
Now here's the weird one...I was trying to use a double array so that I could grow each part. Note how the Len(c) returns 10, the number of elements in the second part. What's odd is that Len(c[0]) returns 0 because the element is null yet Len(c[0][0]) returns 1 because the element has a length of 1. Then it fails to set c[0][0] because it thinks it's out of bounds. So basically the double slice has failed on the first index, but seems OK on the second index (I think).
Maybe I'm trying to use the compiler on a way it's not designed, but I'd really like to have a 2D array that I can grow and shrink (think tile-based level that you may want to alter whenever it's loaded).