Level: siege of stonehold


#1

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


#2

**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


#3
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.


#4

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!


#5

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)

#6

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!


#7

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


#8

I have a question.

Do I defeat Thokar, his minoins, or both?


#9

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


#10

how much health do you need to survive


#11

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.


#13

it says this when i mouse over the x,


#14

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…


#15

how should i define doctor


#16

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.


#17

what does it mean by tmp15


#18

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]”.


#19

thanks a lot i passed
`


#20

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.


#21

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