Restless dead - how to command to attack

can’t to command my troops attack skeletons at the end =( pls help me

# Этот уровень считается ОЧЕНЬ сложным! Чтобы одолеть его, тебе понадобится хорошая стратегия или эпичное барахлишко!

# Найди и убей йети, чтобы добыть его кровь для ритуала.
# Возможно, тебе стоит собрать монеты, которые оставит йети. Они пригодятся, чтобы вызвать подкрепление.
# Встань на ритуальный камень (красная отметка Х) для призвания.
# Теперь всё просто: нужно пережить нашествие орд нежити.
def attack():
    enemy = hero.findNearestEnemy()
    while enemy.health>0:
        if enemy:
            hero.attack(enemy)

def pickC():
    items = hero.findItems()
    while len(items)>0:
        item = hero.findNearestItem()
        hero.move(item.pos)
        items = hero.findItems()
        
def summ():
    while True:
        if hero.gold>hero.costOf('soldier'):
            hero.summon("soldier")

def command():
    soldiers = hero.findFriends()
    enemy = hero.findNearestEnemy()
    if enemy:
        for soldier in soldiers:
            hero.command(soldiers[soldier], "attack", enemy)

hero.moveXY(55, 11)
attack()
pickC()
hero.moveXY(50, 39)
hero.moveXY(19, 40)

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        summ()
        command()

Check if your troops are targeting anyone or they just idle. And I have doubts that this line would work
hero.command(soldiers[soldier], "attack", enemy)
A little bit differs from syntax I used to see in such cases.
Also,

    soldiers = hero.findFriends()
    enemy = hero.findNearestEnemy()
    if enemy:
        for soldier in soldiers:

“soldiers” are defined and “soldier” is not, that may bring troubles.

yeh i was trying all thing i can, even code that working fine in other exercisedidn’t work in this, idk why(

def commandSoldier(soldier):

    enemies = hero.findEnemies()
    for enemy in enemies:
        hero.command(soldier, "attack", enemy)


hero.moveXY(55, 11)
attack()
pickC()
hero.moveXY(50, 39)
hero.moveXY(19, 40)

while True:
    summ()
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":

            commandSoldier(friend)

i start thinkin’ there is some kind of bug in exercise

Is it free level or for subscribers?
Gimme direct link, please, if free.

subscribers i think
https://codecombat.com/play/level/restless-dead?

Yes, subscribers only. I’m not a sub. Maybe I’ll try to have a look at code tonight.

Which pair of glasses are you using? With the twilight glasses, I can get past the Yeti and summon the soldiers. But your summ() function is an infinite loop since you don’t have a condition or break. Add an else statement with a break to get out of the loop or just merge the while loop with the if condition for the same effect.

while hero.gold > hero.costOf('soldier'):

Another issue I see when attacking the Yeti, You want to have the if check before the while loop or add another break in there. Although, if you have the Twilight glasses, this doesn’t cause a problem due to the timing.

    while enemy.health>0:
        if enemy:
            hero.attack(enemy)

Lastly, when commanding the soldiers using a for loop, you don’t need to add the index.

        for soldier in soldiers: # for loops goes through the list of soldiers one by one
            hero.command(soldier, "attack", enemy) 

Although, you will want the hero to be attacking at the final battle to win this one.

1 Like

ty, that help me a lot!