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

[SOLVED] Make Advances

Everything goes fine until the end. My last paladin just stops, and the archers move on and die, how do I make make my paladin move to the very end? Here is what happens:
Screenshot 2020-10-15 at 4.59.14 PM


This is my code:

# Advance through the forgotten tomb.
# Be wary, traps lay in wait to ruin your day!

# The Paladins volunteer to lead the way.
# Command them to shield against incoming projectiles.
while True:
    friends = hero.findFriends()
    # findEnemyMissiles finds all dangerous projectiles.
    projectiles = hero.findEnemyMissiles()
    for friend in friends:
        if friend.type is "paladin":
            # Find the projectile nearest to the friend:
            for projectile in projectiles:
                distance = friend.distanceTo(projectile)
                # If the projectile exists
                # AND is closer than 10 meters to the paladin:
                if projectile and distance < 10:
                    # Command the friend to "shield":
                    hero.command(friend, "shield", friend)
                # ELSE, when there is no potential danger:
                else:
                    # Advance the paladin:
                    hero.command(friend, "move", {"x": friend.pos.x + 50, "y": friend.pos.y})
            pass
        else:
            # If not a paladin, just advance:
            hero.command(friend, "move", {"x": friend.pos.x + 20, "y": friend.pos.y})
        pass
    # Advance the hero in the x direction:
    hero.moveXY(hero.pos.x + 10, hero.pos.y)

2 Likes

Is this past mountain? If so, I cannot help you, sorry :frowning:
Lydia

1 Like

i’m pretty sure this is the link @Lydia_Song https://codecombat.com/play/level/make-advances

weird because for me it says paladins go and attack starting from the left and going to the right

here is where it is located and its not passed mountain

Hi abc,

Instead of:

just use:

            var projectile = friend.findNearest(projectiles);

I also made the friends stay just behind their nearest paladin (otherwise they ran ahead and got killed). And I also put a paladin heal function in, and I had to play around with the distance that the paladins and the hero moved each time to make it work.

Jenny

1 Like

He is in Python, not JavaScript Jenny.
So it would be

projectile = friend.findNearest(hero.findEnemyMissiles())

If I’m not mistaken.
Lydia

1 Like

Good point, thanks Lydia :grin:

2 Likes

If I command the archers to stay back, they survive, but my last paladin stops and lets himself be killed by a fireball

1 Like

The problem here is my bottom paladin, no matter what I do, he always just stops short.

1 Like

is your code still the same??
edit: sorry i cannot help you as when i use your code the problem is different to yours

I tried doing that, but then I only disable my middle trap. My paladins all go for their targets, but my top one doesn’t make it to it’s target because my bottom paladin dies first. I don’t know why, but it keeps killing my bottom paladin.

Unfortunately, I can’t help you, because I haven’t passed the level myself!
Lydia

That’s okay. Now my top paladin is stuck

I finally solved it!

1 Like

Congrats! Altough I did absolutely nothing . . . :sweat_smile:
Lydia

tick the box which helped you the most(even thought you just solved it yourself :rofl:)