Level: Peasant Protection

hey yall i love this game challenges your brain who constucted the game if i may ask

3 Likes

my charecter keeps killingthe peasant no matter what code i put in

3 Likes

Well, what are you telling your hero to “attack”?

3 Likes

i am telling my hero to attack enemy and to shield Victor.

3 Likes

Nevermind i was usin g a purchased sword instead of cleaver! hah…not really
THANK YOU FOR YOUR HELP

3 Likes

I need help with my code
’’’’’’’’’’’’’’’’’’’
’’’’’’’’’’’’’’’’’’'
loop:
enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy)
if distance < 10:
self.attack(enemy)

else:
    self.moveXY(40, 33)

‘’’’’’’’’’’’’’’’’’’
’’’’’’’’’’’’’’’’’’'
It says that there is an “Unexpected Token” on the “Else” line. I’ve just started getting into programming ,besides (Q Basic) and it’s probably some easy mistake, but i’m not really great at python so plz help! :pray:

3 Likes

Tip: To format your code correctly, use three of the `, or backticks, instead of ', the quotation marks.

3 Likes

Your problem is that you have not indented the line self.attack(enemy) inside your if-statement.

4 Likes

loop:
enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy)
if distance < 10 :

    self.attack(enemy) 
else:
    self.moveXY(40,37) 

plz help me~~~


Solved already … but…

Why there are some codes don’t work on my game when I pasted the correct codes I found online?

3 Likes

Maybe the code you found online wasn’t correct in the first place? We have many “solutions” that are bugged, are untested ect.


Generally I advise strongly against using or even searching solutions online. You really just hurt yourself. Try to solve it yourself. If you really can’t get it, search in this forum or in the online documentation of your chosen language. Google is your friend here. If you still can’t solve it and there is no topic here about this problem, then open a new topic. Post your code correctly formatted (***!!!***) as described in the FAQ, write exactly what your problem is and what you have tried to solve it and we will try to solve your problem.

7 Likes

re-check your Looping your looping something that may not exist because there may not always be a distance if there is no enemy try:

Loop:
enemy = self.findNearestEnemy()
if enemy and distanceTo(enemy) < 10
self.attack enemy
else:
self.moveXY(40,37)

3 Likes

Hi I need help here and for Info I don’t use Java.Thanks!

3 Likes

Tell us what are you trying to do and the error message you are receiving. If no error, your observed code behavior and why it is different from what you intended. Format your code by surrounding it by 3 back-quotes (top-left on your keyboard)

code

3 Likes

As @AdrianCgw mentioned, please post your code with radiant and harmonious formatting, as described in the FAQ. Phrases like ''i need help" or “i can’t figure it out” don’t help us help you. Please post your code (with formatting according to the FAQ) , what happens, and anything else that would be helpful.

Cheers! @Luke10

3 Likes

loop:
enemy = self.findNearestEnemy()
if enemy:
distance = self.distanceTo(enemy)
if distance <6:
self.attack(enemy)
else:
self.moveXY(40, 35)
self.say(“Come closer”)
Here is my code.My problem is that every time I go and attack the Ogres, other Ogres will attack the Peasent

3 Likes

Thanks I just can’t get through the level.

3 Likes

Change distance<10 (you allow them to come too near)

if distance<10:

Remove the last line: self.say(“come closer”) , makes your hero idle for 1 second while talking

3 Likes

Thank you so much for the code!It work like genius

3 Likes

Glad to hear that you beat the level. Just remember that from now on, post your code with formatting by reading the FAQ.
Here’s the link:
https://discourse.codecombat.com/faq

3 Likes

No problem but still one thing are you one of their staff @Luke10?

3 Likes