About Multi-Dimensional Arrays...

BlitzMax Forums/BlitzMax Programming/About Multi-Dimensional Arrays...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

So I DID miss something, thanks a lot! xD Good to know, as I prefer those when I don't need to modify the array later. Yes, I know arrays of arrays wasn't proper multi-dimensional arrays, but I always thought BlitzMax somehow didn't support that outside pre-declared arrays and that arrays of arrays was the only way to simulate proper multi-dimensional arrays when starting with an empty array. >_<

Somehow I never found examples of that, and aw, I where just missing that ",", never thought of trying that. =_= *sigh* BlitzMax could really do with some extra lines of explanation in the documentation, oh well. lol.

I'll keep using an array of arrays whenever I need slicing, but it always felt so unnecessary whenever I had an array that doesn't need to be sliced and modified later.

But I noticed in SebHoll's example that you can set both dimensions of an array of array at the same time... So apparently I've missed something there too. From other examples I guess that only works in the cases where you know the values and dimensions ahead though, which is usually not the case when I declare an empty array (not to mention using that on large arrays would require quite a lot of typing! xD).

Anyway, I might been doing it the hard way when it comes to array of arrays too then. So let me give an example of where I find multi-dimensional arrays more suitable than array of arrays, then maybe someone can direct me on a more suitable path again:

Piece of code using multi-dimensional array
SuperStrict

Local MyArray:Int[,]=New Int[20,20]

For Local f1:Int= 0 To 19; For Local f2:Int= 0 To 19
	MyArray[f1,f2]=f1*f2
	Print MyArray[f1,f2]
Next; Next

MyArray=New Int[10,10]	' <--- Resizing array, where old values are cleared

' modification of the array outside this not needed, ever

End
Similar piece of code using array of array
SuperStrict

Local MyArray:Int[][]

MyArray=MyArray[..20]
For Local f1:Int= 0 To 19
	MyArray[f1]=MyArray[f1][..20]
Next

For Local f1:Int= 0 To 19; For Local f2:Int= 0 To 19
	MyArray[f1][f2]=f1*f2
	Print MyArray[f1][f2]
Next; Next

' v--- Resizing the array, but the old values are kept (not always desirable) ---v
MyArray=MyArray[..10]
For Local f1:Int= 0 To 9
	MyArray[f1]=MyArray[f1][..10]
Next

' So have to be cleared in addition
For Local f1:Int= 0 To 9; For Local f2:Int= 0 To 9
	MyArray[f1][f2]=0
Next; Next

End
As you can see from these examples, such code became a lot easier to handle now that I know how to use proper multi-dimensional arrays. ^^; Array of arrays are useful in respective situations, but if they can't achieve the desired effect above in any simpler way wouldn't multi-dimensional arrays be most appropriate instead in those situations? Or is there a simpler way when using array of arrays?

Well, thanks again guys. This have helped me a lot. :3