Whenever I try to put in “hero.findNearestEnemy” it never works.
Here is my code:
currentHealth = hero.health
healingThreshold = hero.maxHealth / 2
enemy = hero.findNearestEnemy()
# 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:
You should get in the habit of always checking for an enemy before attacking, otherwise if there is not an enemy when the code iterates through the attack section, it will return a null error. You’ve already defined enemy as hero.findNearestEnemy() so there’s no need to use this method again. Try this:
if enemy: # <--- More often than not this is a good idea before attacking