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

[SOLVED] Help! Make Advances

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

None, but only my middle paladin moves and shields.
image

Link

https://codecombat.com/play/make-advance

Lydia

  1. link should be https://codecombat.com/play/level/make-advances )
1 Like

Thanks for catching that! I’m on the computor app so . . .
Lydia

1 Like
# Find the projectile nearest to the friend:
            nearestProjectile = hero.findNearest(projectiles)

It might be here…
I tried to change but now get an error with allies move.

1 Like

sorry i can’t help you on this I only have Boss Star I

Try to change condition, merge 2 of them into 1, like.
if nearestProjectile and friend.distanceTo(nearestProjectile) < 10:

And friend.move command looks like hero.command(friend, "move",{"x":friend.pos.x + 10,"y": friend.pos.y})

1 Like

You are finding the nearest projectile towards you, so that will always be the middle projectiles, therefore only the middle paladin can shield from the middle projectiles. Don’t find the nearest projectile loop over all the projectiles.

2 Likes

Now the paladins all move, but they don’t shield.

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

Lydia

in the command friend sheield part im pretty sure you only need hero.command(friend, shield)
in stead of

Nope, still doesn’t shield.
Lydia

try this instead i had a small typo
hero.command(friend, “shield”)

Well I changed the numbers for paladins and hero and non-paladins allies destination and complete the level (one of paladins dies anyway though).
I put 8 instead of 10 for paladins and 5 for hero.
I target other allies to 31,45.

Yes, it still doesn’t work.
Lydia

hmm try turning it to this:
hero.command(friend, “shield”, self)

Thanks Alexbrand! I completed it!
But doesn’t this seem a bit strange to you? image
Lydia

Mine shields, but in a strange manner…

1 Like

Yes, its strange. Maybe there is something about speed.

@cheddarcheese No, hero.command(friend,"shield") is OK.

1 Like

I looked other solutions and as far as I see nobody uses default code guideline completely.

1 Like

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