# Level: Peasant Protection

@JIAN_WEN_CHIN You can see the forum staff in the About section.

3 Likes

So he is not one of their staff

3 Likes

Yeah, but I donât think thatâs very relevant. The forums are public, so anyone can help others and can even help moderating the forum by flagging posts that require staff intervention.

4 Likes

Can someone help? We are trying to open this level and we canât get it to load. The level before it, and the level after it seem to load fine.

I tried to post the log, but it says as a new user I canât have more than 2 links!

Thanks!

3 Likes

Hello,

I am new to this game and a bit frustrated. I read all of the above discussions, and the code Iâm using is the same as code that is said to work many times above, namely:

``````while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if distance < 10:
# Attack if they get too close to the peasant.
hero.attack(enemy)
# Else, stay close to the peasant! Use else.
else:
hero.moveXY(40, 37)
``````

The hints pretty much say to do this exactly (even though, as an experienced programmer, this logic doesnât really make sense to meâŚit says if the distance to the nearest enemy is less than 10, then attack, whereas it would make much more sense if it was the distance from the enemy to the peasant - of course that would involve some more complicated mathsâŚanyway).

Anyway, it seems to me that the problem is my hero has a wand, and itâs just too slow to kill anything. I donât want to spend gems on the wrong weapon having discovered the hard way that gems can cost actual moneyâŚ

Can someone tell me what weapon I need to buy, or otherwise, what the problem is?

Thanks,

2 Likes

Ok, never mind. We didnât realise we could still use the old âfighterâ hero. When we switched the fighter with a sword, all the ogres died. Great!

2 Likes

I absolutely can not beat this level. I have tried everything mentioned above and nothing works. I normally use Python. It has seemingly glitched out. Everything from past attempts is playing at once.

``````while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if distance < 10:
# Attack if they get too close to the peasant.
hero.attack(enemy)
# Else, stay close to the peasant! Use else.
else:
hero.moveXY(40, 37)
``````

I checked the level and its initial code is:

``````while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if distance < 10:
# Attack if they get too close to the peasant.
pass
# Else, stay close to the peasant! Use else.
``````

I think the first lines must be:

``````    enemy = hero.findNearestEnemy()
# delete  distance = hero.distanceTo(enemy)
# you don't know if the enemy exists
# you cannot measure  a distance to non existent enemy
if enemy and hero.distanceTo(enemy) < 10:
``````

If you cannot pass the level with these corrections you maybe are using a very simple sword.
Try to be max closer to the peasant ( increase the y coordinate)

What happens when you run your code? Your code works for me. As xython said, this may be an equipment problem.

no it does not work

so sometimes at the beginning it says can not figure it out google it!
are we allowed to do that J_F_B_M?

Hi @Gabriel_Knight, J_F_B_M is not longer active so he wonât see your post. Also this topic is two years old. If you are not looking for help, thereâs not much point replying to the topic as the people who are in it are no longer active. (except for xython)
Danny

1 Like

oh sorry I did not know thank you for the information.

1 Like