Types, DIM and deleting

Blitz3D Forums/Blitz3D Beginners Area/Types, DIM and deleting

You know when you load an image you do this:

MyImage = Loadimage()


Now if you were to then do this:

MyImage = 1234


The image would then become lost because you altered the MyImage value that stored its location in memory.

The same thing applies to blitz types:

alien.aliens = new aliens


This would create an alien, then if you were to do this:

alien.aliens = new aliens


It would create a new alien, but change the "alien.alien" value so the first one gets lost.

Now to bring that into your example:

Dim galaxy.alien(20)


This line will create 20 "values" each of which can point to only 1 alien at a time. As described above, the moment you overwrite one, it becomes lost.

The way you might want to do it is like so:

Type galaxy
	Field a.alien[100]
End Type

Type alien
	Field name$
End Type

;create some galaxies
For i = 1 To 2
	g.galaxy = New galaxy
	;create some aliens for this galaxies
	For ii = 1 To 100
		g\a.alien[ii] = New alien
		g\a.alien[ii]\name$ = "bob the alien"
	Next
Next