Hey Folks,
I’ve been stuck on this for a while and tried changing it up… but I still can’t get my character to move at all.
Can someone tell me what I’m doing wrong?
Thanks!
# 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."
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, 33)
1 Like
Please use backticks (above the tab button on the keyboard) to format your code, or highlight it and press the < / > button. Alternatively, you could take a screenshot and press the Upload button on a post.
(checking this level / your code right now to see if I can find the problem)
2 Likes
hey sorry… i just read that on the FAQ when I saw that it was pasting improperly… been trying to figure it out … give me a sec! thanks for looking at my post though! should get it fixed soon…
1 Like
alright! just got it formatted correctly… was using ‘’’ instead of ```
1 Like
No problem! Easy mistake to make.
The reason that nothing is happening is because your second while loop isn’t inside your while True
. So basically, highlight everything starting with while enemyIndex < len(enemies)
, and then press the tab button to give it another indentation.
Edit: except make sure you keep hero.moveXY(40, 33) with only four spaces before it.
2 Likes
EDIT***
HA! Thanks! You solved my problem!
In addition, to anyone else who might be looking at this… I also forgot to put enemyIndex += 1 at the bottom… so it kinda looked like this…
# 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
much thanks to taylerzy for the tip!
1 Like
Great!
Might want to edit out you code, though. They don’t allow completed code on here, as it takes some of the fun out of it.
2 Likes
I need help this is my code
while True:
enemies = hero.findEnemies()
enemyIndex = 0
enemies = hero.findNearestEnemy()
# Wrap this logic in a while loop to attack all enemies.
# Find the array's length with: len(enemies)
while True:
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, 33)
my hero is not moving
Try putting the moveXY in the while true loop