Resizing Multidimensional Arrays

BlitzMax Forums/BlitzMax Programming/Resizing Multidimensional Arrays

maverick69(Posted 2005) [#1]
I really like the new slice functions in Blitz, but how can I use them on multidimensional arrays.

A little example

Local ClearField:Int[10, 10]

For local tx=0 to 10
  For local ty=0 to 10
    print Clearfield[tx,ty]
  Next
Next

ClearField[10,..20] '<--- this doesn't work


How can it be done to resize my array ClearField?


PowerPC603(Posted 2005) [#2]
You can't, chech this page at the BlitzWiki:
http://www.blitzwiki.org/index.php/Arrays#Resizing_an_Array_of_Arrays

But you can use arrays of arrays:
' Create empty array of arrays
Local ClearField:Int[][]

' Resize main array to hold 10 subarrays (0...9)
ClearField = ClearField[..10]

' Resize all subarrays to hold 10 elements (0...9)
For Local i = 0 To 9
	ClearField[i] = ClearField[i][..10]
Next



Print ClearField.length ' Prints the size (number of elements) of the main array
Print
For Local m = 0 To 9
	Print ClearField[m].length ' Prints the size of a subarray at each index of the mainarray
Next
Print ' Print an empty line



' Printing the contents of all elements
For Local j = 0 To 9
	Print

	For Local k = 0 To 9
		Print ClearField[j][k]
	Next
Next

' Print an empty line
Print

' Resizing only 1 subarray (the one at main array index 5)
ClearField[5] = ClearField[5][..20]

' Printing the size of all subarrays
For Local l = 0 To 9
	Print ClearField[l].length
Next



maverick69(Posted 2005) [#3]
Thank you, I'll try it later, but I think I have understood it ;-)