Inventory:
My code structure:
My hero does the following (sections):
- Collects gold (until having 20).
-
Moves to the center of the map
{"x":56, "y":45}
(if hero’s gold >= 20) - Summons a “soldier” (if hero’s gold >= 20)
-
Commands the soldier to move to the right of the map
{"x":83,"y":45}
- If there is a near enemy, commands the soldier to attack the enemy until the enemy dies
The problem:
I’ve run the code section by section and all work fine except the while loop
in the last section, it’s running forever!
(Edit):
Also, my minions don’t move/attack unless the location {“x”:56, “y”:45}/enemy is within my hero’s eye-sight.
enemy = hero.findNearestEnemy()
for soldier in hero.findByType("soldier", hero.findFriends()):
hero.command(soldier, "move", {"x":88, "y":47})
if enemy:
while enemy.health > 0:
hero.command(soldier, "attack", enemy)