Level: Peasant Protection


#89

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


#90

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


#91

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


#92

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


#93

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


#96

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:


#97

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


#98

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


#99

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?


#100

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.


#101

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)


#102

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


#103

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


#104

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


#105

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


#106

Thanks I just can’t get through the level.


#107

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


#108

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


#110

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


#111

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