Array of types vs collection of types

BlitzPlus Forums/BlitzPlus Programming/Array of types vs collection of types

Dan60(Posted 2004) [#1]
Do you ever find that 'sometimes' its better to have an array of types instead of a collection of types?

An array of types allows you to access any type with out going through the whole for each loop.

Maybe I'm missing something, and I could accomplish what I want without using the array.


Seldon(Posted 2004) [#2]
I used arrays of types when I needed to reach several exact positions.


QuietBloke(Posted 2004) [#3]
Each has its own strengths and you should use whatever is appropriate for the job.
If I have a tilebased game and I need each tile to hold certain details I would make the tile itself a type but I would create a 2d array to hold the tiles because I will need to access specific tiles based on an x,y position.
In the same game the enemies are spawned from spawn gates. These I can just define as an enemy type and just use the type collection for accessing them because I never need to access specific enemies. My code will always act upon the whole collection when moving, checking for collisions etc.


pantsonhead.com(Posted 2004) [#4]
Arrays of types are definitely the best way in some cases, there's nothing "wrong" with using them (if you use the right code for the jod).