[Solved] Please help Medical Attention


#1

This is my code:

while True:
    currentHealth = hero.health
    healingThreshold = hero.maxHealth / 2
    # If your current health is less than the threshold,
    # move to the healing point and say, "heal me".
    # Otherwise, attack. You'll need to fight hard!
    if currentHealth < healingThreshold:
        hero.moveXY(65, 46)
        hero.say("heal me")
    else:
        enemy = hero.findNearestEnemy()
        hero.attack(enemy)

The yellow duck is telling me that there is an error on the last line but it doesn’t tell me what it is and I can’t figure it out. Please help me!


#2

you forgot to check if the enemy exists.


#3

But I put find nearest enemy


#4

you need to add the if: statement.


#5

You defined enemy, but you need to check if the enemy exists. I just told you that an hour ago in another thread. It’s best to get in the habit now or you’re going to be running into a lot of headaches.