I can't solve the level "ogre encampement"


#1

Hi guys,

I can’t solve this level but I don’t understant what’s wrong…

They say: # If there is an enemy, attack it.

Otherwise, attack the chest!

And my code is:

loop:
    # Use if/else.
    enemy1 = self.findNearestEnemy()
    if enemy1:
        self.attack(enemy1)
        self.attack(enemy1)
        
    else:
        self.attack("Chest")

But I die and I don’t undersant…

Help me please, ty :smile:


#2

Please format your code according to the FAQ. Hint put triple(`) around your code.


#3

And also what programming language are you using. looks like python. If so here’s what I can see.
1st, you don’t need enemy1. It’s already in a loop so it will keep attacking the ogres. 2nd, do you have indentations on your actual code? If not:

enemy1 = self.findNearestEnemy()
if enemy1:
self.attack(enemy1)
self.attack(enemy1)
else:
self.attack("Chest")

Would turn into:

enemy = self.findNearestEnemy()
if enemy:
       self.attack(enemy)
       self.attack(enemy)
else:
   self.attack("Chest")

This is not a bug, it’s simply a coding mistake. If this comes to becoming a bug you can post it on our GitHub issues:

Please :heart: this post if you find it useful
Cheers! :beers:
-@Luke10


#4

Okay ty very much but even if I write what you said, I die…


#5

What does it say? Please explain


#6

And also how much health


#7

I have 120 :heart:
I die at 31. At 18 an ogre comes and my character doesn’t see it and from 19 to 22, he hides behind the chest, than an other ogre (one with a gun) arrive and I kill the two ogres. When I kill them I lose 63 (70->3) :heart: . At 30 I kill an other, I have 5 :heart: And then 1 other comes and I die with him and when I die an other ogre (with a gun) arrive…


#8

Looks like a bug. you should invite @nick


#9

Ty very much :slight_smile: And sorry but I’m a little noob how can I invite nick?


#10

You don’t need to. Luke just did.

Have you tried resubmitting your seed?


#11

Try buying any piece of armor–even the leather gloves will do it. You almost have enough health to beat the level, but not quite.


#12

Oh yes thank you very much everyone! :smile: