You have to use enemy = hero.findNearestEnemy() inside the while true loop before you attack the enemy.
enemy = hero.findNearestEnemy()
Haha of course! why did I not think of that?