Help with Sarven Shepherd [SOLVED]

Hi,
I am stuck, the palyer attacks the first ogre but then he says: …but it’s dead.

Can you help me?

``````# Benutze while-Schleifen, um den Oger rauszusuchen

while True:
enemies = hero.findEnemies()
enemyIndex = 0

# Verbaue diese Logik in einer While-Schleife, um alle Gegner anzugreifen.
# ermittele die Länge des Arrays mit: len(enemies)
while True:
enemy = enemies[enemyIndex]
# "!=" bedeutet "ist nicht gleich."
if enemy:
enemyIndex += 1
if enemy.type != "sand-yak":
# Greife den Gegner an, solange seine Gesundheit größer als 0 ist!
if enemy.health >= 0:
hero.attack(enemy)
pass

# Gehe zwischen den Wellen zurück zur Mitte.
hero.moveXY(40, 32)

``````

He defeats the 1st Enemy but then he doesn’t attack the Second Enemy, instead he is saying: “…but it’s dead”

1 Like

I think I see two different details that could use some modification.

The second while True loop causes your hero to keep attacking the second enemy “… but it’s dead”. Instead of True use the comparison enemyIndex and len(enemies) to break from the second while loop. Also, I see notes to use a while health is greater. Switch the if to while and your hero will attack that one enemy until it is dead.

`while enemy.health >= 0:`

While this didn’t cause issues on this one, keep this in mind for later
The enemyIndex starts at 0 for the first enemy (correct), but before you call the attack command, you increase the index and skip the first enemy.

``````        if enemy:
enemyIndex += 1 # skips over first enemy [0] before attacking
if enemy.type != "sand-yak":
# Greife den Gegner an, solange seine Gesundheit größer als 0 ist!
if enemy.health >= 0:
hero.attack(enemy) # attacks second enemy [1]
``````

Thank you so much, it is now functioning