nested types and deleting them.

Blitz3D Forums/Blitz3D Programming/nested types and deleting them.

How would you go about this? I have a method now, but I don't like it at all.

I have a double loop here, and if a missle hits an enemy the enemy is removed, but I can't remove the missle, because it is looked for in the next loop around.

My current code moves the missle to an off screen area so it can be deleted later, but I don't like doing this.



For m.weapon = Each weapon
	m\xpos=m\xpos+m\xmov
	m\ypos=m\ypos+m\ymov

	For e.enemy = Each enemy
		If distance(e\mesh,m\mesh,1) ; if the missle hits the enemy
			; do misc stuff here
			FreeEntity e\mesh ; delete the enemy mesh
			Delete e ; delete the enemy type
			;Delete m (this is what I want to do, but can't because of the loop)
		EndIf 
	Next 
Next


Easy method: Create an additional field in your m type so that you can mark it for deletion.

Then after your code above just
For m = Each weapon
	If m\destroy = True Then Delete m
Next


A \doomed field is probably the best solution for this sort of problem. I'm hesitant to recommend this, but you could fix the specific problem you have above by doing an Exit after you Delete m.

What's wrong with using Exit? This is exactly what the command is for.

Because what if the weapon is within 1 unit from another entity at the same time?

Well, he says in his code that he wants to delete the weapon at the same time as the enemy i.e. each weapon only kills one enemy. Using Exit would allow this.