Arrays in types

Blitz3D Forums/Blitz3D Beginners Area/Arrays in types

Elendia Starman(Posted 2009) [#1]
Would there happen to be a way to have multidimensional arrays in types (in Blitz3D) without flattening them?


Stevie G(Posted 2009) [#2]
No, Blitz arrays are 1 dimension only so your only options is to flatten, as you put it:

const MaxY = 10
const MaxX = 5

Type MyT
  field Blah
  field Arr[ MaxY * MaxX - 1 ]
End Type

global Test.MyT = new MyT

for y = 0 to MaxY-1
  for x = 0 to MaxX-1
     a = y * MaxX + x
     MyT\Arr[ a ] = Blah
  next
next


Depending on what you're doing an Array of Types may work for you:

const MaxY = 10
const MaxX = 5

Type MyT
  field x#, y#, z#
End Type

Dim ARR.MyT( MaxX-1, MaxY-1)

for y = 0 to MaxY-1
  for x = 0 to MaxX-1
    ARR( x, y ) = new MyT
    ARR( x, y )\x = blah
    ARR( x, y )\y = blah
    ARR( x, y )\z = blah
  next
next



Dr. Vince(Posted 2009) [#3]
Thanks for the Array of Types sample, Stevie G. You saved my day.