# 請教 不知道哪裏錯了？就是不運行

ok first thing:
the length of the array enemies is `len(enemies)`, not enemies.length. Im not sure if enemies.length works, since i never tried it.
second thing:`enemies = hero.findEnemies()` should be in the loop since the array changes as more enemies appear.
the default code of the level is:

``````# 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)

enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!

pass

# Between waves, move back to the center.

``````

What you want to do is follow the tips i now add in the code:

``````# 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.**
while condition:
# Find the array's length with:  len(enemies) <-- this'll help you write the condition
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
**# While the enemy's health is greater than 0, attack it!** <-- inside the if statement condition loop
while condition:
hero.doSomething()
pass

**# Between waves, move back to the center.** <-- do this inside the while loop
hero.moveXY(centerx, centery)
``````

Follow those tips and you can complete the level easily.

1 Like

1 Like

Think you . but still no working.

but still not working,
what’s wrong with the code!

Try doing this:
Instead of `while enemyIndex < len(enemies):`, do this:

``````while True:
if enemyIndex < len(enemies):
#if enemy is not yak:
#attack attack attack
enemyIndex += 1
else:
#move to center
``````

but not yet !!!

Use

``````for enemy in enemies:
#code here

``````

@Chaboi_3000 i don’t think you learn for in the desert…

you just have to put the if in the while loop, so basically highlight everything below line 6 and press tab @Law_VITET

the hero was not go working .i don’t know how to let him gone!!!

Indent and also maybe you need more health?

1 Like

just delete the space on line 6…
COME ON! (not shouting @Chaboi_3000 ) you can do this…

It still doesn’t work !!!

It still so motionless:joy:

Can you video tape it using quicktime player?

@Law_VITET did you press shift + enter to run the code?
if that doesn’t work, then you need better gear.

``````if enemy.health>0:
hero.attack(enemy)
``````

is wrong because of indentation
``````if enemy.health>0: