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

[SOLVED]Sarven Shepard level help

I have been stuck on this for awhile.I dont know whats wrong can someone help pls

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

    
   
while enemyIndex<len(enemies):
    enemy = enemies[enemyIndex]
    if enemy.type != "sand-yak" and enemy.health > 0:
        hero.attack(enemy)
        enemyIndex += 1
        pass

hero.moveXY(40, 32)
    

It has to do with indentations. The ‘while enemyIndex’ loop, needs to be indented, so as to make it an inner loop, or a child loop (member), of the outer ‘while true’ loop.

  • Just to explain, the terms ‘inner loop’ and ‘child loop’ are often used interchangeably. They both imply that there is another loop in the hiarchy (above) that they are working for.
  • This other loop is referred to either the ‘parent loop’, or the ‘outer loop’…all of these terms are correct, it’s just a matter of preference, how you learned, etc.

You will also have at least one other issue, but let’s address that, once you get this one fixed…a bit less confusing that way.

Yep, that looks pretty good. And, you fixed the other issue already…enemyIndex += 1 is properly aligned.

Now, think about when you want to move…

My person hits one person then stops with a red x under him?

As shown above, your moveXY statement is aligned with ‘while true’…that means that it is on the same hierarchical level as the while statement…it also means it will never execute. Instead, it needs to be a member of the while loop, not a peer…it needs to be the final statement of the loop.

wait sorry when i was fixing code i deleted a “o” in hero my bad :sweat_smile:

heh…been there myself. Does the level pass now? If it does, please edit the posts above (except the first one) and remove your code. We don’t want to post solutions, as someone may find that post, copy and paste your code and pass the level without having learned a thing.

1 Like

okay thanks for all the help

1 Like