Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Help with serven shepherd


whats wrong?

# 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 True:
    enemy = enemies[enemyIndex]
    # "!=" means "not equal to."
    if enemy.type != "sand-yak":
        # While the enemy's health is greater than 0, attack it!
        while > 0:

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


You used two while-true loops. Try putting:

enemies = hero.findEnemies()
enemyIndex = 0

…into the second while-true loop that you currently have. Then delete the first one so you’re only left with one. That will hopefully be the code needed to pass the level.


Please give more info about what is happening when you run your code. A screenshot would help


I’m going through CC in JavaScript and my Python skills are… let say young.

I used two while loops:

while (true){ } to wrap around my whole code

while (enemiesIndex < enemies.length){ ... } enemiesIndex +1; to check through each enemyIndex in the enemies array to check if the enemy was not a sand-yak and check if the was greater than 0 before attacking the enemy and returning my hero to the centre position on the map.

The ellipse (or ...) is where you put your “do something” code

I originally put this up in JS and Python but you might learn it better if you have hints rather than the full answer, so I hope this helps you figure it out