Hy guy, i try to complete this level, my summon.soldier attack enemy, but dead without defeat any enemy… this is my code.
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
coin = hero.findNearestItem()
hero.moveXY(coin.pos.x, coin.pos.y)
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
while soldierIndex < len (soldiers) :
hero.command(soldier, "attack", enemy)
soldierIndex +=1
I can see one problem straight away:
~~‘Use move instead of moveXY so you can command constantly.’ This line is important. Read your code carefully and you’ll find the mistake.
Also, make sure you have boots with the move
(not moveXY
) ability: fine boots, compound boots, boots of jumping, boots of leaping etc…
Another specific detail that is also causing problems. The starter code assigns soldier before your while loop so you aren’t commanding every soldier, only the first one. Move the soldier line into the while loop before commanding them to run through all soldiers.
soldier = soldiers[soldierIndex]
while soldierIndex < len (soldiers) :
hero.command(soldier, "attack", enemy)
soldierIndex +=1
Ok… sorry, my english is very bad
coin = hero.findNearestItem()
hero.move(coin.pos)
Thanks, i move the soldier line and the problem is solved…
while soldierIndex < len (soldiers) :
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex +=1