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

[SOLVED] Make Advances Paladins Stopping Help!

Hi, I was working on make advances, but whichever paladin got hit by the first fireball stopped before it was done moving to the finish, which ended up killing an archer. How do I make this stop?

# 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:
            projectiles = hero.findEnemyMissiles()
            # If the projectile exists
            # AND is closer than 10 meters to the paladin:
            for projectile in projectiles:
                if friend.distanceTo(projectile) <= 10:
                    # Command the friend to "shield":
                    hero.command(friend, "shield")
                # ELSE, when there is no potential danger:
                else:
                    # Advance the paladin:
                    hero.command(friend, "move",{'x' : friend.pos.x + 1, 'y' : friend.pos.y})
            pass
        else:
            # If not a paladin, just advance:
            hero.command(friend, "move",{'x' : friend.pos.x + 1, 'y' : friend.pos.y})
        pass
    # Advance the hero in the x direction:
    hero.move({'x':hero.pos.x + 1, 'y':hero.pos.y})


What can I do to stop this?

Here is the mistake. There it is not its place.
Try to put a variabile k and make it 0 after this line:

Then if the paladin shields, then make k=1 and after this line

After that check if k == 0 and if that is true then move the paladin.
Do you need any more assistance at this level?

What if there is no missile?

1 Like

Then the paladin should move. And k will be 0 because the for loop will not take place. So the paladin will move.

Thank you! I didn’t think of commanding the archers to stop! :smiley:

1 Like

Actually, with his code as written, if there is not missile, it will still attempt to execute this line ‘if friend.distanceTo(projectile) <= 10’…this evokes the cooldown at a very inappropriate time.

1 Like