Level: siege of stonehold

hi,
i am playing the level siege of stonehold. I have made up this code that makes my soldier follow the flag and attack enemies when nearby. Its working fine until i want to make me soldier cleave. i know the cleave command BUT i want to make it cleave when it is near the soldiers. While i was playing i would make my soldier walk toward the enemies but it would sometimes cleave along the way and not cleave when i wanted it to.

heres my code:

# You'll need great equipment and strategy to win.
loop:
    enemy = self.findNearestEnemy()
    flag = self.findFlag("green")
    target = enemy

    if flag:
        flagpos = flag.pos
        fx = flag.pos.x
        fy = flag.pos.y
        self.pickUpFlag(flag)
    
    elif enemy:
        self.distanceTo(target)
        self.findNearestEnemy()
        self.attack(enemy) 
    
    elif enemy:
        enemy = self.findNearestEnemy()
        distance = self.distanceTo(enemy.pos)
         if distance < 4: self.isReady("cleave")
             self.cleave(enemy)

I need help on this last code ^^^^^ i want to know what is the best way to make my soldier cleave when near an enemy. I tried putting that same code for cleave on the code above it that was for attacking but it didnā€™t work out well so i just made an individual code. Am i doing it right though? It says it is right but the soldier doesnt even cleave or maybe im not getting close enough? Im not sureā€¦

thanks

1 Like

**I just started the game yesterday and iā€™m on the same lvl as u , idk why u used the variable target it doesnā€™t have any sense , another thing the last code **

if distance < 4: self.isReady("cleave")
             self.cleave(enemy)

Shouldnā€™t be ?

if distance < 4:
      self.isReady("cleave")
      self.cleave(enemy)

one more thing flag colour isnā€™t needed in your code since youā€™re using 1 flag

enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy.pos)
if distance < 4: self.isReady("cleave")
             self.cleave(enemy)

OK, a couple things with this. First, you can do distanceTo(enemy) instead of (enemy.pos) I donā€™t think this will be an issue, just a point.
Secondly, your self.isReady(ā€˜cleaveā€™) is really doing nothing. I think you are wanting to check if cleave is ready and only cleave if it is. Instead, you are checking if it is ready, then cleaving no matter what.

(Like asking your mom if you can have a cookie, then after she answers you go get a cookie regardless of her answer) You need something like:

enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy)
if distance < 4: 
    if self.isReady("cleave"):
             self.cleave(enemy)

You could even combine those two if statements:

enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy)
if distance < 4 and self.isReady("cleave"):
       self.cleave(enemy)

Iā€™m guessing what was happening is that you would run to the enemy position, cleave wasnā€™t ready so youā€™d wait til it was ready, then by that time the enemy was gone.

Iā€™ve been trying to beat this level and my code is super simple atm but it keeps giving me the Fix your Code: Find the distance to a target unit error. Is there something wrong with my code?

loop:
    enemy = self.findNearestEnemy()
    distance = self.distanceTo(enemy)
    if distance < 20 and self.isReady("cleave"):
            self.cleave(enemy)
    else:
            self.attack(enemy)

I altered the code to this and Iā€™m not sure why itā€™s working nowā€¦ @_@

loop:
    enemy = self.findNearestEnemy()
    flag = self.findFlag()
    # If there is an enemy, attack it!
    if flag:    
            flagpos = flag.pos
            fx = flagpos.x
            fy = flagpos.y
            self.moveXY(fx, fy)
            self.pickUpFlag(flag)
            
            if enemy:
                    distance = self.distanceTo(enemy)
                if distance < 10:
                    self.isReady("cleave")
                    self.cleave(enemy)
                
        elif enemy:
            if distance < 10:
                self.attack(enemy)

edit: AHH I beat it!! Yay!

Not sure if bug or not , but self.distanceto(target.pos) ainā€™t working in this lvl and now you need to to it directly in a new if statment like this

if enemy:
                    distance = self.distanceTo(enemy)
                if distance < 10:
                    self.isReady("cleave")
                    self.cleave(enemy)

HELP! I canā€™t get past this level. It seems impossible. This is my code:
loop:
enemy = self.findNearestEnemy()
flag = self.findFlag(ā€œgreenā€)
if flag:
self.pickUpFlag(flag)
elif enemy:
if self.isReady(ā€œcleaveā€):
self.cleave(enemy)
else:
self.attack(enemy)
Whenever I place a flag, I mean for my player to go to it and pick it up, but it doesnā€™t. Do I need to start fresh? I have over 600 health and the long sword. PLEASE HELP!

Everything looks good to me as long as you are placing green flags. Are you possibly placing the wrong color flag?

I have a question.

Do I defeat Thokar, his minoins, or both?

Just the minions. Thoktar is nearly invincible, but will go away if you kill all his guys.

how much health do you need to survive

Depends on your strat. It CAN be done with 236 HP, with a really really good strat. :slight_smile:

I believe @nick recommends ~400+ hp for most people.

it says this when i mouse over the x,

As strange as it may seem I believe the problem is the 2pos on line 12.

You cant have a number as the first character of a variable name. so make it pos, twoPos, pos2, flagPos, fPos, etcā€¦

how should i define doctor

You use some sort of find command and hunt the doctor down and use it, or if the doctor never moves, then you can just manually set it and be done.

If I remember correctly, you go to the mouth of the ā€œvillage/keep/whateverā€ to get healed so point your mouse there to get the coords and set it manually.

what does it mean by tmp15

Your code gets translated in to javascript usable by ā€œAetherā€ (the code that controls the processing of the game). This process rewrites and wraps your code up so it can be run in a controlled fashion (catch infinite loops, take turns, etc). It assigns a ā€œtmp#ā€ variable to everything (yes, essentially EVERYTHING). So ā€œpos = doctor.posā€ becomes something like: ā€œtmp14 = tmp16[tmp17]ā€.

thanks a lot i passed
`

I think there is a major bug with this level now.
Thoktar constantly resurrect already dead ogres!
So level cannot be completed with any gear.
FYI: Iā€™m using Chrome.

Thanks for the heads up; I saw the same thing. Not sure what changed, but Iā€™ve restricted Thoktarā€™s raise dead range now.