Level: Odd Sandstorm - I can't find out what's wrong


I’ve written my code for this level over and over, but it won’t work, and I can’t find out what’s wrong. There are no error messages, the hero just completely ignores my while loop.

I’ve posted my code here in hope that someone can please help me! Thank you!

# This array contains friends and ogres.
# The even elements are ogres, but the odds are friends.
everybody = ['Yetu', 'Tabitha', 'Rasha', 'Max', 'Yazul',  'Todd']
enemyIndex = 0

while enemyIndex < len(everybody):
    # Use square brackets to get the ogre name from the array.
    enemy = everybody[enemyIndex]
    # Attack using the variable holding the ogre name.
    if enemy:
        while enemy.health > 0:
    # Increment by 2 to skip over friends.
    enemyIndex += 2

# After defeating ogres, move to the oasis.
self.moveXY(36, 54)


When you say ‘doesn’t obey the code’, what happens? Does you’re character just not move, or does something happen that you don’t expect?


Well, I not used to python, but I tried your code. I removed the while loop. I still had error due to indentation (I should really start over the campain in python), but I succeded the level. Now that I’m thinking about it, the array everybody contains strings but not units. You can target by name, but the method .health is applied on units not strings. This is why the while loop is never executed : “whateverString”.health won’t return anyting ever. So your while loop is equivalent to while false. Hope this helps ! :smile:

Btw, this topic isn’t a bug (see topic tag in the topic list).


Thanks for your help! So you’re saying that it was my enemy.health loop that was the problem. The .heath only works with units, not strings. It all seems so simple now!

But if I can’t use while enemy.health > 0, how would I make a loop to kill an enemy when I don’t know how many hits it needs to die? Is that possible?


You pause the playback or wait until it finishes, then click on one of the throwers, dead or alive, and point at their health bar to see how many hp they have (if not full, if full then you don’t need to point at it to know.) (Throwers usually/almost-always/should have 7 hp, so unless you are using Simple Sword, Crude Crossbow, Large Bolt Crossbow, Oak Crossbow, Enchanted Stick, Simple Wand, or Twisted Pine Wand, you should be good to kill with one swipe.)