Sarven shepherd help plz

help

# Use while loops to pick out the ogre

while True:
    enemies = hero.findEnemies()
    enemyIndex = 0

    # Wrap this logic in a while loop to attack all enemies.
    # Find the array's length with:  len(enemies)
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    # "!=" means "not equal to."
    if enemy.type != "sand-yak":
        # While the enemy's health is greater than 0, attack it!
        while enemy.health > 0:
            hero.attack(enemy)
        enemyIndex += 1
        pass

    # Between waves, move back to the center.
    hero.moveXY(40, 33)

I suggest you change out the

to

for enemy in enemies

I dont recall the for loop being in the desert. At that level while loops are used.

You should backspace the one below to be at the end of the second while loop and not in the if condition

2 Likes

And you should also indent all the code from the second while loop to make it inside the first one

1 Like

yea Aya is right, the only time u use for loops is probably Shine Getter I think…

2 Likes

And it should probably be after the pass statement, otherwise the loop will break before moving back to the center.

1 Like

like this?

# Use while loops to pick out the ogre

while True:
    enemies = hero.findEnemies()
    enemyIndex = 0

    # Wrap this logic in a while loop to attack all enemies.
    # Find the array's length with:  len(enemies)
for enemy in enemies:
    enemy = enemies[enemyIndex]
    # "!=" means "not equal to."
    if enemy.type != "sand-yak":
        # While the enemy's health is greater than 0, attack it!
        while enemy.health > 0:
            hero.attack(enemy)
        enemyIndex += 1
        pass

    # Between waves, move back to the center.
    hero.moveXY(40, 33)

nevermind I got it (20)

Good job :+1:

if you solved the level, please mark the post as a solution for thetopic to close, and if you couldnt, we’ll be more than happy to help :slight_smile:

1 Like

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