[SOLVED] Yeti Eater plz hlp

here is my current code:

# Defeat them in the order from weakest to the strongest.

# The wizard sorted enemies, but in the order from the strongest to the weakest.
wizard = hero.findNearest(hero.findFriends())
yetis = wizard.findEnemies()

# You need iterate the yetis list in the reverse order with a 'for-loop'.
# The start value should be 'len(yetis) - 1'.
# Iterate while the index greater than -1.
# Use the negative step -1.
yetiIndex = len(yetis) - 1
for yeti in yetis:
    # Attack each enemy while its health greater than 0.
    for yeti.health > 0:
        hero.attack(yeti)
    
    yetiIndex -= 1

the error is on this line:

    for yeti.health > 0:

and the error says: “there is a problem with your code” and thats all it says plz hlp

1 Like

Can you send me the link to this level?
Lydia

2 Likes

https://codecombat.com/play/level/yeti-eater?

2 Likes

Did you read this line?
Lydia

1 Like

what about that line?

2 Likes

I think that it is saying

while yetiIndex > -1:

Try that.
Lydia

1 Like

if i do that then my hero goes for the strongest yeti

2 Likes

Try to write:

for i  in range(len(yetis) - 1, -1, -1):
    while yetis[i].health > 0:

And attack yetis [ i ].

1 Like

now there is another error saying this: " attack’s argument target should have type object, but got null. target is null. is there a target?

2 Likes

here is code:

# Defeat them in the order from weakest to the strongest.

# The wizard sorted enemies, but in the order from the strongest to the weakest.
wizard = hero.findNearest(hero.findFriends())
yetis = wizard.findEnemies()

# You need iterate the yetis list in the reverse order with a 'for-loop'.
# The start value should be 'len(yetis) - 1'.
# Iterate while the index greater than -1.
# Use the negative step -1.
yetiIndex = len(yetis) - 1
for yeti in yetis:
    # Attack each enemy while its health greater than 0.
    for i  in range(len(yetis) - 1, -1, -1):
    while yetis[i].health > 0:
        hero.attack(yeti [i])
    
    yetiIndex -= 1
2 Likes

You have to delete these parts.

2 Likes

both of the top lines? @PeterPalov

1 Like

here is the error:
Screenshot (29)
and the code:

# Defeat them in the order from weakest to the strongest.

# The wizard sorted enemies, but in the order from the strongest to the weakest.
wizard = hero.findNearest(hero.findFriends())
yetis = wizard.findEnemies()

# You need iterate the yetis list in the reverse order with a 'for-loop'.
# The start value should be 'len(yetis) - 1'.
# Iterate while the index greater than -1.
# Use the negative step -1.
# Attack each enemy while its health greater than 0.
for i  in range(len(yetis) - 1, -1, -1):
    while yetis[i].health > 0:
        hero.attack("yeti [i]")
    

error is here

        hero.attack("yeti [i]")
1 Like

Try to write:

hero.attack(yeti[i])

“” is used in attacks when you target enemies by their name, but this is not the case here, don’t you think @098765432123?

Andrei

so when i take out the “yeti [i]” there is an error saying to put " "

1 Like

and also what are u saying AnseDra?

1 Like

Look closer at the array in what the yeties are hold in. Do you see anything wrong with the array that you are using to attack? I said that you do not need “” when you are using variables, you only use them when you target enemies by their name as you did in the dungeon.

Andrei

2 Likes

i solved it! thanks @AnSeDra and @PeterPalov for helping me.

3 Likes

No problem! Anytime! And congratulations for completing the level! :partying_face:

Andrei

2 Likes