Whenever I run the code my hero just stands there. Please help me.
# Use while loops to pick out the ogre
loop:
enemies = self.findEnemies()
enemyIndex = 0
# Wrap this logic in a while loop to attack all enemies.
while enemyIndex < enemies:
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:
self.attack(enemy)
enemyIndex += 1
pass
# Between waves, move back to the center.
self.moveXY(40,32)
Thanks a ton. I’ve been having trouble with while loops and now I see my error. Yet I still can’t get it right. when I run my updated code my hero kills two ogres then moves back to 40, 32. Then the “While enemyIndex < len(enemies)” I get a hard execution limit error. What am I doing wrong?
Use while loops to pick out the ogre
loop:
enemies = self.findEnemies()
enemyIndex = 1
Wrap this logic in a while loop to attack all enemies.
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!
self.attack(enemy)
enemyIndex += 1
# Between waves, move back to the center.
self.moveXY(40,32)
I breezed through the first initial 300 levels, it was simple enough, but on this level a slew of new definitions and functions come about and I am completely lost, been stuck for three weeks I really need help, I’ve tried absolutely everything.
The “while True” function overrides everything as long as your main value is true, so everything else has to be within it. That was the problem I had, at least.
help, this is my code:
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.”
if enemy.type != “sand-yak”:
# While the enemy’s health is greater than 0, attack it!
while enemy health > 0:
hero.attack(enemy)
enemyIndex += 1
pass
# Between waves, move back to the center.
hero.moveXY(40, 32)
it says that i need a : after while enemy health > 0: