The only error is that my attack code gets null, even though enemy = hero.findNearestEnemy was directly above it. Heres my code.
# Ask the healer for help when you're under one-half health.
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, please!")
elif currentHealth > healingThreshold:
enemy = hero.findNearestEnemy()
hero.attack(enemy)
You need find the enemy, which you have done, but you can only attack it if it exists, so you should do an if enemy:, and then have your attack statement inside of the if loop. The reason for if statements is that there is not always that something, in this case there is not always an enemy for your hero to attack.
# Ask the healer for help when you're under one-half health.
enemy = hero.findNearestEnemy()
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, please!")
else:
if enemy:
hero.attack(enemy)
At the moment you find an enemy at the start (outside the while True loop), but once you’ve killed that enemy you don’t find another enemy. What line of code do you need to move to do this?