GLBasic forum

Main forum => GLBasic - en => Topic started by: PeeJay on 2008-Jan-14

Title: Help - Type problem
Post by: PeeJay on 2008-Jan-14
I'm sure this is just me being stupid, but I have a problem with the following code that I can't figure out.

It is code to do a collision detection between shots fired and enemies

Code (glbasic) Select
FOREACH en IN enemies[]
LOCAL enemyhit=FALSE
FOREACH sh IN shots[]
IF SPRCOLL (2,sh.x,sh.y,3,en.x,en.y)
DELETE sh
enemyhit=TRUE
ENDIF
NEXT
IF enemyhit=TRUE
DELETE en
ENDIF
NEXT
When run, the shots are being deleted okay, but the enemies are not. Anyone know why?!?
Title: Help - Type problem
Post by: Moru on 2008-Jan-14
After a delete command, the code under it gets skipped and the loop continues from the top again. Always use delete at the end of the loop if you expect it to execute the rest.

Try moving the Delete command under enemyhit=TRUE
Title: Help - Type problem
Post by: PeeJay on 2008-Jan-14
Ah, thanks for that Moru - I knew it mush have been me being stupid :)