Baffled By Arrays

BlitzMax Forums/BlitzMax Programming/Baffled By 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.

Is the slice of 2 making all of the 'array of arrays' with just 2 Dimensions (for the info recording of x and y)?


Yes. (well two elements rather than dimensions, it is still a 1D array) It loops through each of the elements of the main array and resizes the array that those elements contain.

Ok, what makes the first line an array of arrays rather than a two dimensional array? Is the syntax different for a two dimensional array?

The two seperate square braces [][] define it as an array of arrays.

To define a two dimensional array you would do:
Local myArray:Int[,]

The comma denotes a new dimension in the current array

Then on the second line, shouldn't there be another bracket set after the [..MaxStars] since two sets were used in the declaration?

No, because the slice re-dimensions the main array, not the arrays it contains.

It *might* help to think of the main array as a list of Types where each type is another array.

Just to complicate things, you could also do:
Local myArray:Int[][,] 


Which would create an array of 2D arrays

I recently added a page to the BlitzWiki which covers arrays to a certain degree (part of it is the original BMax array docs).

http://www.blitzwiki.org/index.php/Arrays

Perhaps I should really read up on the whole slice thing! Sounds a bit like ReDim in many BASICs, but with more flexibility.


Slices are great! (missing one particular bit of functionality I would like, but hey you can't have everything at once).

It should be pointed out that you cannot use slices with Multi-Dimensional Arrays.