I'm using arrays to quickly pinpoint a specific type.
Let's say I've got 200 sectors and 20 stations per sector.
This is equal to 4000 type-instances.
Now, the player can only be in one sector of space at any given time (like Freelancer).
So, to loop through all stations in the sector where the player is located, I would only have to loop through all indexes of the array for that sector, instead of looping through all 4000 type-instances:
The var "CurrentSector%" holds the current sectornumber where the player is located.
Without using arrays (and need updating all stations inside the current sector), I would have to do something like this:
Looping through all stations (where 99.5% of them (3980 out of the total 4000) don't need to be checked) is a bit overkill when only updating 1 sector.
But now I have succesfully converted my loading routines into BMax, using resizable arrays-of-types inside types.
No more trouble about unused array-indexes.
Now I have actually what I wanted, except a 3D module, to create an entire sector and fly through it, of course (which my B3D-version could do right now).
Now I can add stations to a sector, without having to know the maximum number of stations that exist inside a given sector (the most populated one) to firstly dim the array to the proper size, before loading data into it.
Each time a station is added now, the array-size is increased by 1 (the contents don't get lost in BMax) and the new station is added to the sector.
Let's say I've got 200 sectors and 20 stations per sector.
This is equal to 4000 type-instances.
Now, the player can only be in one sector of space at any given time (like Freelancer).
So, to loop through all stations in the sector where the player is located, I would only have to loop through all indexes of the array for that sector, instead of looping through all 4000 type-instances:
; this code print only the 20 stations inside the current sector ; where the player is located For i = 1 To 20 Print ArrayStations(CurrentSector%, i).Name$ Next
The var "CurrentSector%" holds the current sectornumber where the player is located.
Without using arrays (and need updating all stations inside the current sector), I would have to do something like this:
For CurrentStation.Station = Each Station If CurrentStation\BelongsToSector$ = SectorName$ ... EndIf Next
Looping through all stations (where 99.5% of them (3980 out of the total 4000) don't need to be checked) is a bit overkill when only updating 1 sector.
But now I have succesfully converted my loading routines into BMax, using resizable arrays-of-types inside types.
No more trouble about unused array-indexes.
Now I have actually what I wanted, except a 3D module, to create an entire sector and fly through it, of course (which my B3D-version could do right now).
Now I can add stations to a sector, without having to know the maximum number of stations that exist inside a given sector (the most populated one) to firstly dim the array to the proper size, before loading data into it.
Each time a station is added now, the array-size is increased by 1 (the contents don't get lost in BMax) and the new station is added to the sector.