Arrays of a 2d Arrays Madness!
BlitzMax Forums/BlitzMax Beginners Area/Arrays of a 2d Arrays Madness!
| ||
Ok I've got in a bit of a pickle. Conceptially it works out. I have some small 2D grids in [,] format. I want an array of these. Conceptially I don't want a 3D grid, just a series of 2D grids. To make it worse I need to be able to send a 2D grid as a parameter to a function. I've done some experimenting but not suprisingly no luck. For a start should I be doing array[][,] or array[,][]? And these are arrays of a type so I'll be needing to new them. And finally pass one as a parameter like func(array[i]). Sorry for all these questions! |
| ||
SuperStrict Local array%[20,20] foo(array) Function foo(n%[,]) End Function |
| ||
Thanks but that only makes one 2D array. I'm looking to have an array of 2D arrays. |
| ||
maybe thisSuperStrict Type SetType Field array:Int[10,10] End Type Local maps:settype[10] foo(maps) Function foo(n:settype[]) For Local i% = 0 Until 10 n[i] = New settype For Local y% = 0 Until 10 For Local x% = 0 Until 10 n[i].array[y,x] = Rnd(100) Next Next Next End Function |
| ||
That's looking better. I was hoping to do it without introducing a new type but I guess it would be an easier to use solution. |
| ||
I'm at work, so can't test, but wouldn't this be an array of 2D arrays?Function foo(n:Int[][,]) End Function |
| ||
Looks like it. |
| ||
yes, but how do you declare an array of that format? this is what I have: SuperStrict Local array%[,][] array = array[..10] For Local i% = 0 Until array.length array[i] = New Int[10,10] Next foo(array) Print fun(array) Function foo(n%[,][]) For Local i% = 0 Until n.length For Local y% = 0 Until 10 For Local x% = 0 Until 10 n[i][x,y] = Rnd(10) Next Next Next End Function Function fun(n%[,][]) For Local i% = 0 Until 10 For Local y% = 0 Until 10 For Local x% = 0 Until 10 Print n[i][x,y] Next Print "++"+y Next Print "======"+i Next End Function see how I created it and how I am using it. it doesn't make sence. the declaration doesn't match the usage. I tryed to do it the correct way and I keep getting errors. is this a bug? or is there something I don't understand? |
| ||
*EDIT* removed cos' it's crap. I would imagine that the declaration is that way because the type specifier precedes the array i.e. f:Float[] is a float array so f:Float[,][] is an array of float arrays. or something like that. |