[Solved] Please help Medical Attention


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")
        enemy = hero.findNearestEnemy()

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!


you forgot to check if the enemy exists.


But I put find nearest enemy


you need to add the if: statement.


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.