I’m having an issue with an infinite loop on Summit’s gate in regards to the catapult health:
def attackCatapults():
catapults = self.findByType("catapult")
for catapult in catapults:
while catapult.health > 0:
self.attack(catapult)
def moveForward():
self.move({'x': self.pos.x + 1, 'y': self.pos.y})
loop:
attackCatapults()
moveForward()
After the hero defeats the catapults, he gets stuck in self.attack(catapult) even though the catapult health is not greater than 0.
Edit: It looks like .health isn’t the issue, the hero is trying to attack a catapult that is not visible to me (likely near the end of the level?) It’s difficult to debug this one without knowing what my hero is seeing since it’s not visible or within line-of-sight.
Your code looks fine. If I recall correctly, there are only two catapults in this level.
Isn’t it the moveForward() function where you are getting stuck at? That will move the hero forward until they walk against a wall, and keep forcing their way against the wall without success.
For future reference: self.say(catapults)
Would have let you see what your hero was seeing.
My guess is that you were having a problem with a empty list. You ran through the code once and your second loop you tried to run it through again, but there were no catapults. This led your hero to do crazy things, as you told him to attack a non-existent catapult.
You can try:
def attackCatapults():
catapults = self.findByType("catapult")
if len(catapults):
for catapult in catapults:
while catapult.health > 0:
self.attack(catapult)
To see if it works, but your current code is better anyway (I wish I would have used that for summit’s gate)