Storming the Farmhouse

How do you beat this?

I’ve tried quite a few things and the your “Hero” dies way to fast and moves to slow to protect anyone

Even if you just sit right next to the peasants and sheild and wait for cleave you still git run over and one of them dies.

Getting kinda of frustrated here. :/

We can’t help unless we see what is going on with your code.

Can you please copy and post it here, surrounding it with the code brackets?

```Code goes here.```

I’ve rewritten the code about 12 times by now. Here is the lastest iteration.

`# Soldiers will slowly arrive, but the ogres will overwhelm them.

A basic attack loop isn’t going to be enough to keep you alive.

while True:
flag = self.findFlag()
enemy = self.findNearestEnemy()
if flag:
self.pickUpFlag(flag)
if(self.distanceTo(enemy) <5):
if(self.isReady(“cleave”)):
self.cleave(enemy)
else:
self.attack(enemy)
self.attack(enemy)
else:

    if(self.distanceTo(enemy) <5):     < ----- Null?
        if(self.isReady("cleave")):
            self.cleave(enemy)
        else:
            self.attack(enemy)
            self.attack(enemy)
    else:
        self.moveXY(49, 37)

`

It keeps calling that part null idk why It should work.

Also the formating thing is terrible and why can I scroll the website while inside the text box for commenting?

New code:

# Soldiers will slowly arrive, but the ogres will overwhelm them.
# A basic attack loop isn't going to be enough to keep you alive.
while True:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    if flag:
        self.pickUpFlag(flag)
        if(self.distanceTo(enemy) <5):
            if(self.isReady("cleave")):
                self.cleave(enemy)
            else:
                self.attack(enemy)
                self.attack(enemy)
    else:
        self.moveXY(49, 37)
        if(self.distanceTo(enemy) <=5):
            if(self.isReady("cleave")):
                self.cleave(enemy)
            else:
                self.attack(enemy)
                self.attack(enemy)
        else:
            self.moveXY(49, 37)

formating doesnt work for some reason

I fixed your formatting for you.

Note what it is saying is ‘null’. You are checking for the distance to an enemy, which may, or may not exist.

Further you say your code is ‘slow,’ but if there is no flag, you are repeatably moving back to a point before each attack. This could slow down your code.

Ok I wrote new code and now the dude doesnt even move at all

while True:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    if flag:
        self.pickUpFlag(flag)
    else:
        if(enemy):
            if(self.distanceTo(enemy) <=5):
                if(self.isReady("cleave")):
                    self.cleave(enemy)
            else:
                while(enemy):
                    if(self.distanceTo(enemy) <=5):
                        self.attack(enemy)

He doesnt even attack or move if threre is a flag

Well I firgured out how to get it to run but apparently I’ve hit the hard limit of 3000000

so yeah…

while (enemy): Is your problem. You have a loop in a loop. As long as there is an enemy on the screen your character will wait and check to see if there is one within 5 and ignore all other commands. This will happen 3000000 times in a few seconds. Delete the second loop. You don’t need it.

Also you can simplify your code to make it easier to read with 2 little steps.
elif:
is the same as

else:
    if:

Using the word “and” lets you check for multiple things in the order listed. The same as:

if:
    if:

Simplified it would look like this (which I find much easier for me to read and makes it more likely I won’t make mistakes)

    elif enemy and self.distanceTo(enemy) <=5:
        if self.isReady("cleave"):
            self.cleave(enemy)
        else:
            self.attack(enemy)

I made the edits in the code but I still die before the rangers. Is there some trick to beating this level?

If you are in campaign… buy better equipment.

I haven’t tried playing in courses mode, but letting the soldiers absorb damage for you or running forward and shielding may work.

And you can always just let the peasants die…

At least the code is working now :smile: