Help with Storming the farmhouse


#1

I am working on storming the farm house mission and have been trying to do the following action:
I would like my hero to move to the flag then check to see if there is an enemy less than 10 away if so cleave if ready, else bash if ready else attack if cleave and bash are not ready. Then sheild if enemy is greater than 10 away. What I get is move to flag and check to see enemy and random cleaves and bashes but no attacking and no shielding. Any thoughts on what I can check to improve my code?
Code:

loop:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    distance = self.distanceTo(enemy)
    if flag:
        self.say("Maybe I should do something with that flag?")
        self.pickUpFlag(flag)
        if enemy:
            if distance < 10:
               ready = self.isReady("cleave")
               if ready:
                  self.cleave(enemy)
               else:
                  self.attack(enemy)
            elif distance > 10:
                 self.shield()
            else:
                 pass
         else:
              pass

#2

Of course. First, learn how to format your code by reading the FAQ so that we can get to the actual part of helping you with your code. I’ll do it for you, but just this once.

You should probably define your enemy and distance after you move to the flag, so that you actually attack the nearest enemy, and not the nearest before you moved. Also, there is nothing about bashing in your code.


#3

Will give that a try.

Thanks


#4

Moved the enemy and distance definitions to after flag placement and added the bash definition. It seems to be working better but still not seeing my hero attacking if cleave and bash are not ready. Also not sure shield is being used.

  1. Do I need to define shield and/or see if it is ready before using it?
  2. Am I putting too many actions (cleave, bash) before attack?

code:

loop:
    flag = self.findFlag()
    if flag:
        self.say("Maybe I should do something with that flag?")
        self.pickUpFlag(flag)
        enemy = self.findNearestEnemy()
        distance = self.distanceTo(enemy)
        if enemy:
            if distance < 10:
               ready = self.isReady("cleave")
               bash = self.isReady("bash")
               if ready:
                  self.cleave(enemy)
               elif bash:
                   self.bash(enemy)
               else:
                  self.attack(enemy)
            elif distance > 10:
                 self.shield()
            else:
                 pass
         else:
              pass

#5
  1. No, shield has little to no cooldown.
  2. No, of course not. I use more actions before attack than that.

Get rid of the else: pass clauses. They do nothing and will not affect the code if removed. Also, you can just use else: instead of elif distance > 10:. Either distance must be less than 10 or not; there is no middle ground. Also, you should probably define distance inside if enemy:.


#6

Made corrections and think the code is working but I think the problem is now that I don’t have enough health to survive the wave.

Code:

oop:
    flag = self.findFlag()
    if flag:
        self.say("Maybe I should do something with that flag?")
        self.pickUpFlag(flag)
        enemy = self.findNearestEnemy()
        distance = self.distanceTo(enemy)
        if enemy:
            if distance < 10:
               ready = self.isReady("cleave")
               bash = self.isReady("bash")
               if ready:
                  self.cleave(enemy)
               elif bash:
                   self.bash(enemy)
               else:
                  self.attack(enemy)
            else: 
                 self.shield()

#7

Try getting rid of the say command. It serves no purpose except to stall you.