# Use while loops to pick out the ogre
while True: # This is your outer (parent) loop
enemies = hero.findEnemies()
enemyIndex = 0
if enemyIndex < len(enemies): # Change this to a while loop; it is an inner loop, or child loop
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak": # Need to indent these, as they are members of the 1st child loop
# While the enemy's health is greater than 0, attack it!
while enemy.health > 0: # This is another inner loop, or a step-child, as it is a member of the 1st child loop
hero.attack(enemy)
pass
enemyIndex += 1
# Between waves, move back to the center.
hero.moveXY(40, 32)
I made the alterations suggested above and your code works!
You didn’t change the if to a while…line 4, as counted from the above code. You also didn’t indent line 5-9, to make that block a child of the new while loop. Finally, you didn’t indent line 12…it is the final statement of the outer loop.
# Use while loops to pick out the ogre
while True: # This is your outer (parent) loop
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies): # Change this to a while loop; it is an inner loop, or child loop
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak": # Need to indent these, as they are members of the 1st child loop
# While the enemy's health is greater than 0, attack it!
while enemy.health > 0: # This is another inner loop, or a step-child, as it is a member of the 1st child loop
hero.attack(enemy)
pass
enemyIndex += 1
# Between waves, move back to the center.
hero.moveXY(40, 32)
Yes and @CodingGeek14, I’m afraid I’m also going to ask you to delete the solution in this topic: https://discourse.codecombat.com/t/python-help-anyone/20604/10
I know it’s a bit annoying, but we can’t have solutions readily available for peoples use or it could ruin the game for some people.
Thanks
Danny
# Use your new "cleave" skill as often as you can.
hero.moveXY(23, 23)
while True:
enemy = hero.findNearestEnemy()
if hero.isReady("cleave"):
# Cleave the enemy!
hero.cleave(enemy)
pass
else:
# Else (if cleave isn't ready), do your normal attack.
hero.attack(enemy)
pass
Also, I edited the comment you showed me so that it doesn’t show the solution.
Plus, his code before my comment worked anyway and he didn’t want my solution.
return #Commented out to stop infinite loop.
# 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."
enemy = hero.findNearestEnemy()
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)