[Solved] Operation "Killdeer" Help


#1

This is my code:

def shouldRun():
    if hero.health < hero.maxHealth / 2:
        return True
    else:
        return False

while True:
    # Move to the X only if shouldRun() returns True
    if shouldRun():
        hero.moveXY(75, 37)
    # Else, attack!
    else:
        hero.attack(enemy)

But when I run my code, the hero kills one ogres before letting the other ogres kill him. Please help!


#2

Inside your while True loop, what is an enemy? You need to define the variable. Also, it’s a good idea to get in the habit of checking for the existence of an enemy before attacking it. You’re going to run into that a lot so save yourself the headache and just start doing it now. In this situation, you can use elif enemy instead of else.


#3

Usually a duck hero will tell you to do that, as an error message. Probably to motivate kids,I don’t think it motivates me at all. ;(