Bonemender - enemy not an object?

# Heal allied soldiers to survive the siege.
while True:
    if hero.canCast("regen"):
        bernardDistance = hero.distanceTo("Bernard")
        if bernardDistance < 10:
            # "Bernard" needs regeneration!
            hero.cast("regen", "Bernard")
        
        # Use "if" and "distanceTo" to regenerate "Chandra"
        # if she is closer than 10 meters away.
        chandraDistance = hero.distanceTo("Chandra")
        if chandraDistance < 10:
            hero.cast("regen", "Chandra")
        
    else:
        # If you aren't casting "regen", use "if" and "distanceTo"
        # to attack enemies that are closer than hero.attackRange.
        
        enemy = hero.findNearestEnemy()
        if hero.distanceTo(enemy) < hero.attackRange:
            hero.attack(enemy)
        
        pass

This is what I’ve gotten to, however in the line with ‘if hero.distanceTo(enemy) < hero.attackRange’ it says that the object enemy is null. What am I doing wrong here?

Well, there’s situations where there isn’t an enemy. Try checking if there’s an enemy by adding an and enemy in that if statement.

1 Like

That’s exactly what I did, and it worked. Thanks!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.