Ah, I see the problem (in your original code).
On line 5, you’re using enemy = hero.findEnemies(), which means that you’re returning an array instead of a single unit.
An array contains multiple enemies, so CodeCombat wouldn’t know which one you’re trying to find the distance to.
Replacing hero.findEnemies()
with hero.findNearestEnemy()
should fix your problem.
1 Like