[Solved]Help with make advances


#1

Do you know what I am doing wrong?
Thanks!

# 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)


#2

The

is wrong, you can’t check if there’s an array but you can check a single object, which you’ve defined above.
Hope this helps, if not get Chaboi3000 or MunkeyShynes. (summon them)


#3

I always check if there is an array, is that really wrong?
/Didn’t check what is wrong with the code above/
edit:
Checked what is wrong :slight_smile:

You and your archers need to be always behind the paladins. So I created an array of paladins:

    paladins = hero.findByType('paladin', hero.findFriends())

changed this line:

            # if projectiles and friend.distanceTo(closestProjectile) < 10:
            if closestProjectile and friend.distanceTo(closestProjectile) < 10:

Here you commanded your hero to move ahead, but you really must command your archers and they must follow the nearest paladin

        else:
            # If not a paladin, just advance:
            # hero.moveXY(hero.pos.x + 1, hero.pos.y)
            leader = friend.findNearest(paladins)
            hero.command(friend, 'move', leader.pos)

the hero also must follow the nearest paladin

    # Advance the hero in the x direction:
    # hero.moveXY(hero.pos.x + 1, hero.pos.y)
    leader = hero.findNearest(paladins)
    hero.move(leader.pos)

Change the boots, if they don’t allow move. The above solution is only a quick fix, it’s sure not the best one :slight_smile:


#4

Thanks I solved it!:grinning: