can DIM be defined with types?

Blitz3D Forums/Blitz3D Programming/can DIM be defined with types?

Dimas(Posted 2010) [#1]
I have 100 zones.

I want to store x,y, and some other values for each zone (for my example, x&y willm do)

It would be ideal to use types

But I also need direct access to a zone. Currently I do:

dim zones(100,1) ;0=x 1=y
xx=zones(24,0)
print "X coordinate of zone 24 is "+xx

But it would be great to do:

type zz
field x
field y
end type
dim zones\zz(100)
xx=zones\x(24,0)
print "X coordinate of zone 24 is "+xx

But it doenst work or I am doing it wrong.

Is there a way to access types directly by numbers? (my 100 zones do not change, they are always 100 of them)


Warner(Posted 2010) [#2]
It works, but you need to use "." instead of "\"
Type ZZ
  Field x,y
End Type

Dim zones.ZZ(100)
zones(0) = new ZZ
zones(1) = new ZZ
zones(2) = new ZZ

zones(0)\x = 10
zones(0)\y = 12



Dimas(Posted 2010) [#3]
Thankyou!


Osoko(Posted 2010) [#4]
How to iterate into this using the "each" command ?


Ross C(Posted 2010) [#5]
You would simply use a loop the same as a normal array.


Warner(Posted 2010) [#6]
Indeed:
For i = 0 to 100
   if zones(i) <> null then print zones(i)\x
Next

Or:
For z.ZZ = each ZZ
   print z\x
Next