Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Village Guard Level Unsolvable

#1

I can’t seem to complete the level ‘Village guard’. I can’t get my warrioir to move to the right entrance intime, although at first i was able to do that, but then it owuldn’t go back to the left entrance intime to get the last ogre. it is supper, super, so very very veyr very freaking frustrating. I would reeeeeaaaallllyyyy like some help before i bite through my hand in frustration or something… PS I’m using python and the script I wrote is something like this:
loop:
self.moveXY(60, 31)

  rightEnemy = self.findNearestEnemy()
  if rightEnemy:
      self.attack(rightEnemy)
      self.attack(rightEnemy)   

,
Basically after the left side is defended my hero just stands there until the first right ogre comes and then the hero can’t get to the right in time to save the villager.

#2

Please, format your code correctly. There is a button for that : </> . If you don’t know how to use it, please read FAQ.

```
enemy = self.findNearestEnemy()
if enemy:
    self.attack(enemy)
```

Trying to decipher what you’re trying to say and working on it. Is this you whole code up there ? Because there are several obvious reason why it’s not working.

#3

the whole code is something like

loop:
    self.moveXY(35, 34)
    leftEnemy = self.findNearestEnemy()
    if leftEnemy:
        self.attack(leftEnemy)
        self.attack(leftEnemy)
    # Now move to the right entrance.
    # Use "if" to attack if there is an enemy.
  loop:
      self.moveXY(60, 31)
      rightEnemy = self.findNearestEnemy()
      if rightEnemy:
          self.attack(rightEnemy)
          self.attack(rightEnemy)
#4

but what happens is that it just stays at (35,34) until the ogre shows up at about (60,31) and then it can’t get to the villager in time.

#5

You have two nested loops, which is why it doesn’t work as you’d like to work. The first part of the code, checks if there is an enemy on the left, which is fine. After that, you redo a loop in the loop : while on the left, check if there is someone on the right. Make it simpler with only one loop ! If you can’t find the solution, i’ll come back in 30min to help more.

On a general rule, having two nested loops is -usually- a not so good idea.

#6

thx. that worked. can’t believe the whole time i was doign the wrong hting! facepalm

#10

loop:
self.moveXY(35, 34)
leftEnemy = self.findNearestEnemy()
if leftEnemy:
self.attack(leftEnemy)
self.attack(leftEnemy)
# Now move to the right entrance.
# Use “if” to attack if there is an enemy.
loop:
self.moveXY(60, 31)
rightEnemy = self.findNearestEnemy()
if rightEnemy:
self.attack(rightEnemy)
self.attack(rightEnemy)
self.moveXY(35, 34)
ye = self.findNearestEnemy()
if ye:
self.attack(ye)
self.attack(ye)
self.moveXY(60, 31)

#11

Okay, so there’s a piece of code. Why is it there?

#12
# This function attacks the nearest enemy.
def findAndAttackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

def findAndCleaveEnemy():
    if hero.isReady("cleave"):
        findAndCleaveEnemy

while True:
    def findAndAttackEnemy():
        hero.moveXY(35, 34)
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    
    def findAndCleaveEnemy():
        if hero.isReady("cleave"):
            hero.cleave(enemy)
    
hero.moveXY(60, 31)
findAndCleaveEnemy()
findAndAttackEnemy()

thats my code for village warder but I can’t find any reason why I cannot beat it. My hero only attacks one and doesn’t cleave. I do not know what run time error I have.

#13

help please ive tried for long but nothing was right

#14

Can you post your code so we can assist you to finishing the level.

#15
 while True:
#     hero.moveXY(35, 34)
#     leftEnemy = hero.findNearestEnemy()
#     if leftEnemy:
#         hero.attack(leftEnemy)
#         hero.attack(leftEnemy)

#     # Now move to the right entrance.
#     hero.moveXY(60, 31)
#     # Use findNearestEnemy again to find the right enemy.
#     rightenemy = hero.findNearestEnemy()
#     # Use "if" to attack twice if there is a right enemy.
#     if rightenemy:
#         hero.attack(rightenemy)
#         hero.attack(rightenemy)
        
        
while True:
    
    self.moveXY(35, 34)
    leftEnemy = self.findNearestEnemy()
    if leftEnemy:
        self.attack(leftEnemy)
        self.attack(leftEnemy)
    # Now move to the right entrance.
    # Use "if" to attack if there is an enemy.
    self.moveXY(60, 31)
    rightEnemy = self.findNearestEnemy()
    if rightEnemy:
        self.attack(rightEnemy)
        self.attack(rightEnemy)

is my code

#16

What happens when you run the code? Are you getting an error message?

#17

Your first while True loop is empty, since you’ve commented out everything inside it, giving you an error, probably.

#18

@MunkeyShynes is it possible to code a bot that will automatically return any errors in the user’s code?

Also is it possible to code it so that if a user has keywords in their post, such as “help” + “code”, “I don’t get it”, etc., for there to be an auto prompt for them to post their code?

#19

no when i run it i miss the ogre

#20

please post a screen shot of the equipment you’re using in this level.

#21

#22

Pender is just too weak to kill effectively and quickly enough in this situation. Maybe if you had better gear it would work but not using your present setup. Try changing your hero to a warrior and equip with the best sword you have. Also, if you have the softened leather boots use them because they’re a little faster.

#23

thanks it worked! but now i am stuck on ogre encampment