Types in an Array
BlitzMax Forums/BlitzMax Programming/Types in an Array
| ||
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? |
| ||
IIRC you can put types in an array. For types and relatives, have a look here: http://blitzwiki.org/index.php/Object_Oriented_Programming |
| ||
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. |
| ||
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... |
| ||
oops yeah I forgot to mentionthat. Furthermore you might want to manually clean them out when killing the array. |
| ||
Thanks that works awesome! |
| ||
here is another example: |
| ||
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 |
| ||
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: |