Dynamic 2D Array
BlitzMax Forums/BlitzMax Beginners Area/Dynamic 2D Array
| ||
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. |
| ||
Is a one-dimensional array an option? adress=array[x+width*y] |
| ||
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. |
| ||
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 :) |