Arrays Global

Blitz3D Forums/Blitz3D Beginners Area/Arrays Global

ThePict(Posted 2011) [#1]
Are arrays by default Global? I have to Dim them outside of a Function for the function to work with them, and wondered if they'd be accessible in other parts of my code outwith the function.


Yasha(Posted 2011) [#2]
Yes. You can't have local Dim arrays, unfortunately. However, you can re-Dim them at any time, so you can sort-of free very large arrays when done by resizing them to zero (note: re-Dim-ing an array will lose its contents even if you resize it to something other than zero).

If you really need local arrays, there's the "Blitz array" option which is declared the same way as a variable but with square brackets after the name containing the size of the single dimension. These can have local, global or field scope (and can be passed in to functions, which is actually useful in a lot of ways) but you can't resize them; they have to be a compile-time constant size.


ThePict(Posted 2011) [#3]
I'm quite old-school with my coding and the "Blitz array" sounds very much like what I'm used to.
I'm very taken with the re-Dim-able array though - and I've never quite gotten into Types - so I've re-written my functions and reDimming them as required and completely overwhelmingly satisfied with the wonders of Blitz