In need of tips for Siege of Stonehold. (Not because it's too hard.)

I’m doing Siege of Stonehold right now. What I’m trying to do is make Tharin walk to a flag and sit on a flag even if he sees enemies along the way until enemies are near then cleave them. Once that’s done he will attack the rest and then run to the Violet flag until cleave is ready again. This is hard though, because he sees a bunch of dead ogres nearby and cleaves them. I’m not sure how to go about this.

He is also moving to the violet flag when I’m telling him not to and he won’t pick the flag up once he cleaves it says to pass an object… Guys please =(

# You'll need great equipment and strategy to win.
    enemy = self.findNearestEnemy()
    flag = self.findFlag()
    item = self.findNearestItem()
    cleave = self.isReady("cleave")
    if enemy:
        distance = self.distanceTo(self.findNearestEnemy())
        if flag != "Violet":
            if cleave == 1:
                self.say("Cleave Ready!")
                flagP = flag.pos
                x = flagP.x
                y = flagP.y
                self.moveXY(x, y)
                if distance < 6:
                    self.moveXY(x, y)
                    if enemy:
                        if flag:
                            self.pickUpFlag("Green" or "Black")
    elif cleave == 0:
        vPos = flag.pos
        x = flag.pos
        y = flag.pos
        self.moveXY(x, y)
        self.say("all clear!")

I believe that this is python, and I use javascript, but regardless, is seems that you are telling Tharin to move to XY if distance < 6. But, before that, you defined x as the x coordinate of the flag, and y as the y coordinate of the flag, so you’re telling him to move to the flag and then cleave enemy? Maybe you should make two more variables, say, ex and ey (enemy x and enemy y), and define them as the coordinate of the enemy. Then, you could tell him to move there and cleave the enemy. As for the part where he cleaves dead enemies… I’m not sure, but it might be a bug. Once again, I’m not sure whether this would work, but you might try it out. Also, have you beat this level yet?

Also, the way you are using flag colors, though it would also make sense, isn’t the way that it works. Use them like this:

if flag != "Violet":
should be
if flag.color != "violet":

self.pickUpFlag("Green" or "Black")
should be

should be
flag = self.findFlag("violet")

I put moveXY twice like that to make sure that he moves to the flag then even if he encounters an enemy alone the way he still moves wherever the flag is before engaging them.

Oh okay for some reason I thought the flag colors were capital. Thanks to you both for the help.