[Tutor] break
Matthew Ngaha
chigga101 at gmail.com
Thu Mar 14 23:38:41 CET 2013
i cant seem to break out of this loop. let me explain the variables you see:
Enemy.ships = [] #an Enemy class variable that contains enemy ships
self.missiles = [] an instance variable that appends how many Visible
missiles my ship has fired
Enemy.rects = [] an Enemy class variable that represents a rectangle
for every ship in Enemy.ships
Explosion() = a class where explosions occur
QPoint() = is a pyqt function that takes a point x, y position as arguments
im trying to destroy the ships if they hit a missile, even though i
use pyqt this is mainly python code
if Enemy.ships:
for missile in self.missiles:
for rect in Enemy.rects:
if QPoint(missile.x + 5, missile.y) in rect:
explosion = Explosion(rect.x(), rect.y())
self.explosions.append(explosion)
break
once the missile has hit 1 Enemy.rect i want to break and go to the
next missile so the missile is destroyed and doesnt hit another Enemy,
but for some reason the break i have isnt working and the same missile
sometimes is hitting 2 different rects on the same iteration. i have
done the same loop using a simple print statements on strings greater
than a certain length and it breaks correctly. anyone have any ideas
why the break isnt breaking out of the nested/inner loop but instead
continuing to loop through the Enemies?
More information about the Tutor
mailing list