Getting pointers from array

Blitz3D Forums/Blitz3D Beginners Area/Getting pointers from array

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I've got this testprogram:

Type Station
	Field Name$
	Field FileName$
	Field PosX%
	Field PosY%
	Field PosZ%
End Type

Dim ArrayStations.Station(15, 10)

For i = 1 To 15
	For j = 1 To 10
		ArrayStations(i, j) = New Station
	Next
Next

For i = 1 To 10
	Print ArrayStations(1, i)
Next

WaitKey()


But it gives an error on the line with the Print-command.

My intension was to have a different amount of (space)stations in each sector of space.
The first index-number (1-15) of the array is used as the sectornumber, the second one is used as the stationnumber.
One given sector may contain all 10 stations, where other sectors may contain only 1.

Since it is unneccessary to create ALL type-instances (which consumes memory if you have lots of fields), I only create a new type-instance when there's supposed to be a station in that sector (I read all data from txt-files, which works perfectly).

For looping through all stations in a specific sector, I thought I could check if the index of the array is bigger than "0".
If it is, do some stuff with the data of that type-instance.

I thought this would work, as a pointer is (AFAIK) just a memory-address, which is an integer.
This way I could check if a specific arrayindex held a value bigger than "0".
If it was bigger, than it would point to a type-instance and the station exists.

In this example, in sector 2 exists only 3 stations (not 10):
For i = 1 To 10
	If ArrayStations(2, i) <> 0 Then
		; do stuff here with the data of this type-instance
	EndIf
Next


But it doesn't work, as I get "Illegal type conversion error" on the IF-statement.

Now I bypassed this approach with some extra fields in another type (which existed also) and is used by another array, which hold the exact number of stations each sector contains.

Type Sector
	Field Name$
	Field StationsInSector%
End Type

Type Station
	Field Name$
	Field FileName$
	Field PosX%
	Field PosY%
	Field PosZ%
End Type

Dim ArraySectors.Sector(15)
Dim ArrayStations.Station(15, 10)

; Fill the sector-array with pointers to all sector-instances
For i = 1 To 15
	ArraySectors(i) = New Sector
Next

; some other routines come here to load data from txt-files, which also state
; the number of stations in each sector

; Only create type-instances for the number of stations in each sector which are needed
For i = 1 To 15
	For j = 1 To ArraySectors(i)\StationsInSector%
		ArrayStations(i, j) = New Station
	Next
Next

; Here are some routines which load data from the txt-file
; and put all values into the fields of the type-instances

; print the name of all stations in the galaxy
For i = 1 To 15
	For j = 1 To ArraySectors(i)\StationsInSector%
		Print ArrayStations(i, j)\Name$
	Next
Next

WaitKey()


In this last example, the program creates only the type-instances which are needed, to save some memory (unused type-instances are a total waste).
So if all sectors would have only 1 station in them, then only 1 secondary index (the second indexnumber) is a valid link to a type-instance.

Is there no other way of doing this?
I know I could loop through ALL Station-type-instances (which have a field which holds the name of the sector they are located in), but this would be too big/long.
As all routines in the game only need to know data about stuff in the sector where the player is located (cannot be in 2 or more sectors at once).