Help on Make Advances!

here 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:
            closestProjectile = friend.findNearest(projectiles)
            # If the projectile exists
            # AND is closer than 10 meters to the paladin:
            if projectiles and friend.distanceTo(closestProjectile) < 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.moveXY(hero.pos.x + 1, hero.pos.y)
        pass
    # Advance the hero in the x direction:
    hero.moveXY(hero.pos.x + 1, hero.pos.y)

@AnSeDra

help on make advances

Two things:

Here you want to check if the closestProjectile exists, rather than asking about all the projectiles.

Here you want the other (non paladin) friends to move forward, but keeping behind (ie pos.x less than) the paladin.

2 Likes

Have you completed this level, @ww2_tanker?

Andrei

no? :frowning_face: :sweat:

Can you show me your recent code?

Andrei

Here:

# 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:
            closestProjectile = friend.findNearest(projectiles)
            # If the projectile exists
            # AND is closer than 10 meters to the paladin:
            if projectiles and friend.distanceTo(closestProjectile) < 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.moveXY(hero.pos.x + 1, hero.pos.y)
        pass
    # Advance the hero in the x direction:
    hero.moveXY(hero.pos.x + 1, hero.pos.y)

Why do you check here if an array exists when you should check an object that you just put in a variabile?

Andrei

And you forgot to correct this, too.

Andrei

Don’t get it :no_mouth:

@AnSeDra

@ww2_tanker

On what do you need more clarificafion, @ww2_tanker?

Andrei

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.