Problems with Types

Blitz3D Forums/Blitz3D Beginners Area/Problems with Types

I'm pretty sure I already answered this before. You need to put some error trapping in there. You can't be sure that any entity has been collided with or that that entity is actually a target.

Also, you hide the entity as soon as it collides with something so it will never make the second part of the condition.

Indent your code - it makes it so much easier to debug.

Type bullet
	Field count
	Field shape
End Type

ammo.bullet=New bullet
ammo\count=100
ammo\shape=LoadSprite("Shot 1.bmp")
ScaleSprite ammo\shape,.2,.2
EntityType ammo\shape,type_missile
EntityRadius ammo\shape,.02
HideEntity ammo\shape

Type target
	Field count
	Field shape
End Type

For x=1 To 5
	For z=1 To 5
		foe.target=New target
		foe\count=25
		foe\shape=CreateCube()
		ScaleEntity foe\shape,2,2,2
		PositionEntity foe\shape,Rand(-600,800)+x*5,60,Rand(-600,800)+z*5
		EntityType foe\shape,type_target
		EntityRadius foe\shape,5,5
		NameEntity foe\shape,Handle(foe) ;<<<I’m not quite sure why I put this in here
	Next
Next

While Not KeyDown(1)

	;Firing Bullets
	If MouseHit(1) And reload=0
		EntityParent ammo\shape,gun
		PositionEntity ammo\shape,1,-7,10
		RotateEntity ammo\shape,0,90,0
		ShowEntity ammo\shape
		EntityParent ammo\shape,0
		PlaySound SOUNDbam
		ammo\count=ammo\count-1
	EndIf
	
	bulletpath( ammo.bullet )
	
	UpdateWorld
	RenderWorld
	Flip
	
Wend

End

Function bulletpath( ammo.bullet )
	
	MoveEntity ammo\shape,.043,-.025,2.5
	If CountCollisions(ammo\shape) > 0
		entity = EntityCollided(ammo\shape,type_target)
		If entity > 0
			foe.target = Object.target(EntityName(entity))
			If foe <> Null
				HideEntity foe\shape
				HideEntity ammo\shape
			Else
				HideEntity ammo\shape
			EndIf
		EndIf
	EndIf
	
End Function