redim array?

BlitzMax Forums/BlitzMax Beginners Area/redim array?

slenkar(Posted 2009) [#1]
I searched the forums and found this from 4 years ago:

Local MyArray:Int[20, 50]

MyArray = MyArray[.. 21, .. 51]

but it doesnt run in the latest blitzmax

how do you resize multidimensional arrays?


_Skully(Posted 2009) [#2]
The slice operator only works with single dimension arrays...


Czar Flavius(Posted 2009) [#3]
Try creating a temporary array of size 21, 51 then using a double for loop copy from the original to the temporary. Then make MyArray equal temporary. It's an ugly solution, but should work ;)


Zeke(Posted 2009) [#4]
Strict
Local a[2,2]

a[0 , 0] = 1
a[0 , 1] = 2
a[1 , 0] = 3
a[1 , 1] = 4

Local b[ 3,3 ] 'create b (temp array)
b = a 'copy a array to b

a = New Int[3 , 3] 'resize a array
a=b 'copy b array to back a

^^ this is not working.. you must use double loop.. to copy a array to b and then b array back to a

Strict
Local a[ 2,2 ]

a[0 , 0] = 1
a[0 , 1] = 2
a[1 , 0] = 3
a[1 , 1] = 4

Local b[ 3 , 3] 'temp array

For Local i = 0 To 1
	For Local t = 0 To 1
		b[i , t] = a[i , t] 'copy a array to b
	Next
Next

a = New Int[3 , 3] 'resize a array

For Local i = 0 To 1
	For Local t = 0 To 1
		a[i , t] = b[i , t] 'copy from b(temp) array back to (resized) a array
	Next
Next



slenkar(Posted 2009) [#5]
thanks


Czar Flavius(Posted 2009) [#6]
Is the second loop necessary? Can't you just say a = b?