Help with serven shepherd


#1

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 enemy.health > 0:
            hero.attack(enemy)
        pass

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

#2

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.


#3

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


#4

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 enemies.health 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