Blitz3D+ Language Reference

Multidimensional Arrays

Extended only. Original Blitz Dim arrays are one-dimensional. Select Extended mode to use fixed-size square-bracket arrays with two or more dimensions.

Declaration

Local name:ElementType[upperBound, upperBound [, upperBound ...]]

Every upper bound is inclusive, zero-based, and must be a non-negative compile-time Int constant. A bound of 7 therefore provides indices 0 through 7. The total element count is the product of the size of every dimension:

Local grid:Int[7, 5]  ; (7 + 1) * (5 + 1) = 48 elements

Fixed arrays may contain Int, Float, String, concrete-Type, or Interface values. A single bound declares a one-dimensional fixed array; comma-separated bounds declare a multidimensional fixed array.

Reading and writing elements

Supply exactly one square-bracket index for every declared dimension. Each index is checked against its dimension's inclusive upper bound in debug builds.

Local terrainHeight:Float[127, 127]

terrainHeight[10, 20] = 4.5
Print terrainHeight[10, 20]

Additional bounds create additional dimensions:

Local lightLevel:Float[31, 23, 7]

lightLevel[4, 12, 2] = 0.75

The first dimension varies fastest in memory. Bounds and total allocation size are checked by the compiler so an invalid or overflowing declaration is rejected.

Storage contexts

Multidimensional fixed arrays may be locals, globals, custom-Type fields, and Function parameters. A parameter includes the exact bounds expected by the Function:

Global board:Int[7, 7]

Type Level
    Field tiles:Int[31, 31]
End Type

Function LastCell:Int(values:Int[1, 2])
    Return values[1, 2]
End Function

All storage is allocated with its variable or containing object and cannot be resized. Fixed arrays cannot be assigned or returned as whole values, and collection Types cannot be nested inside them.

Original arrays

Use the one-dimensional Dim form when writing Original-mode code:

Dim values%(10)
values(3) = 25

See Arrays for Original-mode declaration, resizing, element types, and custom-Type array rules.