Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Help! Restless Dead [Python]

But I didn’t test this code. I just correct @Lydia_Song’s code. Maybe it isn’t working.

1 Like

Ok, but I wanted to say that you should try to let @Lydia_Song correct the code herself and not correct it and then send the code because she also must learn how to correct the code herself.

Andrei

5 Likes

Ok, I deleted it, but everyone can click on the"pensil"and see this program.

3 Likes

What hero and equipment did you guys use for restless dead and passed it? PLease Help!!

1 Like

Show me your equipments, I honestly don’t think it the equipments matter as much.

1 Like

This is my newly and revised code. But it says that in hero.command(friend, “attack”, enemy), it should have a unit, not a number. Please HElp!

while True:
    enemy = hero.findNearestEnemy()
    
    item = hero.findNearestItem()
    
    if enemy:
        
        if hero.isReady("throw"):
            hero.throw(enemy)
        else:
            hero.attack(enemy)
    elif item:
        hero.moveXY(item.pos.x, item.pos.y)
    
    elif hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
        
        friends = hero.findFriends()
        
        if friends:
            for friend in range(len(friends)):
                hero.command(friend, "attack", enemy)
        
    else:
        hero.moveXY(19, 40)
                    
2 Likes


I’m using Naria of the Leaf(ranger)

1 Like

You don’t need this part delete it. because you already have for friend

Try correcting this part to for friend in friends

Hope it helps

1 Like

Do you have a higher boss star or is it all you have.

1 Like

This is all I have. (20)

1 Like

Like this?
image

1 Like

Yes, try like that. (20 chars)

1 Like

My soldiers still won’t move.

while True:
    enemy = hero.findNearestEnemy()
    
    item = hero.findNearestItem()
    
    if enemy:
        
        if hero.isReady("throw"):
            hero.throw(enemy)
        else:
            hero.attack(enemy)
    elif item:
        hero.moveXY(item.pos.x, item.pos.y)
    
    elif hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
        
        friends = hero.findFriends()
        for friend in friends:
            hero.command(friend, "attack", enemy)
        
    else:
        hero.moveXY(19, 40)
          
1 Like

Sorry I made an error you didn’t find the enemy for soldiers.
Try this

   friends = hero.findFriends()
        for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)
2 Likes


I Don’t know why but the soldiers still just stand there and do nothing!!! (They’re lazy)

while True:
    enemy = hero.findNearestEnemy()
    
    item = hero.findNearestItem()
    
    if enemy:
        
        if hero.isReady("throw"):
            hero.throw(enemy)
        else:
            hero.attack(enemy)
    elif item:
        hero.moveXY(item.pos.x, item.pos.y)
    
    elif hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
        
        friends = hero.findFriends()
        for friend in friends:
            enemy = friend.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
        
    else:
        hero.moveXY(19, 40)
                    
2 Likes

Can you summon archers?

2 Likes

I dont think so. It’s 1 boss star.
Try:

friends = hero.findFriends()
if friends:
        for friend in friends:
            if friend:
                enemy = friend.findNearestEnemy()
                if enemy:
                    hero.command(friend, "attack", enemy)

I hope it’ll work.

2 Likes

In all these “fors” you always have to write

if friends:
        for friend in friends:
            if friend:

Or you can use:

friends = hero.findFriends()
if friends
for i in range(len(friends)):
    friend = friends[i]
    if friend:
       hero.command(friend, what you want to do)
3 Likes

Thats just more complicated, you can just do this.

for friend in hero.findFriends():
    if friend and friend.type == "soldier":
        enemy = friend.findNearestEnemy()
            if enemy:
                hero.command(friend, "attack", enemy)
3 Likes

No, you have to write:

friends = hero.findFriends()
if friends:
   for friend in friends:
      if friend:
      
2 Likes