Dynamic 2D Array

BlitzMax Forums/BlitzMax Beginners Area/Dynamic 2D Array

Czar Flavius(Posted 2007) [#1]
Hello. I'm having difficulty making a dynamic 2D array. I only know the sizes of the array during run time. Although it might look like I haven't done anything, I have actually tried all kinds of combinations and things but I just can't seem to get it to work.

I want to create an array board[x][y] of custom type boardtype.

Please help.


CS_TBL(Posted 2007) [#2]
Is a one-dimensional array an option? adress=array[x+width*y]


Who was John Galt?(Posted 2007) [#3]
Type square
 	Field piece
End Type

Local board:square[0,0]
sizex=100
siezy=100
board=New square[sizex,sizey]
For x=0 To sizex-1
	For y=0 To sizey-1
		board[x,y]=New square
	Next
Next

This compiles, but I haven't tested it thoroughly. It took some fiddling to get it working properly, so this could do with documenting.


Czar Flavius(Posted 2007) [#4]
Thanks. I realised that I forgot to call the function that actually sets up the array >_<. However I changed my code to Nomen's style and now it works fine.

A 1D array could be an option but if I can get 2D then I'll use it :)