Types in an Array

BlitzMax Forums/BlitzMax Programming/Types in an Array

CASO(Posted 2006) [#1]
Can you put a type into an array or access a type variable using numbers similar to an array so you can single out certain ones?


Sub_Zero(Posted 2006) [#2]
IIRC you can put types in an array.

For types and relatives, have a look here: http://blitzwiki.org/index.php/Object_Oriented_Programming


Grey Alien(Posted 2006) [#3]
yep, you just create a normal variable of the type you want and stick [100] on the end (replace 100 of course) e.g

Local Coords:TPoint[MAX_POINTS]

Then you can do Coords[0].X = 5 or Coords[55].Y = 10 etc.


TomToad(Posted 2006) [#4]
When you create an array of types, you are only creating NULL pointers. You must remember to initialize the elements before using the array.
Local Coords:TPoint[MAX_POINTS]

For Local t:Int = 0 to MAX_POINTS - 1
     Coords[t] = New TPoint
Next

Coords[0].X = 5
etc...



Grey Alien(Posted 2006) [#5]
oops yeah I forgot to mentionthat. Furthermore you might want to manually clean them out when killing the array.


CASO(Posted 2006) [#6]
Thanks that works awesome!


bradford6(Posted 2006) [#7]
here is another example:




Grey Alien(Posted 2006) [#8]
lol @ bradford6, nice one. Actually it's one of the methods I was discussing in this thread that no one replied to:

http://www.blitzbasic.com/Community/posts.php?topic=60050


bradford6(Posted 2006) [#9]
this one is a lttle better. this will dynamically resize the Array as you add and delete elements:

the speed of arrays with some of the useability of lists

the cool thing about this is that an instance of an object can have an array of "instances of another type".

could be useful for lots of stuff that changes.

I'll knock up a different example later: