Help Summits Gate

Ok so this is the last level of this world and my code works perfect i just get stuck against the wall at the very end and i run out of time. Can someone help me?
This is the code

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
# Fight your way into the Inner Sanctum of the ogre chieftain, and kill her.
self.toggleFlowers(False)
def commandArchers():
    for archer in self.findByType("archer", self.findFriends()):
        nearestEnemy = archer.findNearestEnemy()
        if nearestEnemy:
            self.command(archer, "attack", nearestEnemy)
def commandSoldiers():
    for soldier in self.findByType("soldier", self.findFriends()):
        nearestEnemy = soldier.findNearestEnemy()
        if nearestEnemy:
            self.command(soldier, "attack", nearestEnemy)         
def commandGriffins():
    for griffin in self.findByType("griffin-rider", self.findFriends()):
        enemies = griffin.findEnemies()
        nearestEnemy = self.findNearest(enemies)
        if nearestEnemy:
            self.command(griffin, "attack", nearestEnemy)
        else:
            self.command(griffin, "defend", self)
def weakestFriend():
    weakestFriend = None
    weakestHealth = 999
    for friend in self.findFriends():
        if friend.health < friend.maxHealth and friend.health < weakestHealth:
            weakestHealth = friend.health
            weakestFriend = friend
    if weakestFriend:
        return weakestFriend
def commandPaladins():
    for paladin in self.findByType("paladin", self.findFriends()):
        if paladin.canCast("heal", self):
            if self.health < 3000:
                self.command(paladin, "cast", "heal", self)
            else:
                weakestFriend2 = weakestFriend()
                if weakestFriend2:
                    self.command(paladin, "cast", "heal", weakestFriend2)
        else:
            self.command(paladin, "move", {'x': self.pos.x - 4, 'y': self.pos.y})
def summonGriffin():
    if self.gold >= self.costOf("griffin-rider"):
        self.summon("griffin-rider")
def moveForward():
    targetPos = {'x': 328, 'y': 35}
    self.move(targetPos)
def pickTarget():
    enemies = self.findEnemies()
    target = None
    minDistance = 9999
    for enemy in enemies:
        if enemy.type is not "door":
            if enemy.type is "catapult":
                target = enemy
                break
            elif enemy.type is "warlock":
                target = enemy
                break
            elif enemy.type is "witch":
                target = enemy
                break
            elif enemy.type is "chieftain":
                target = enemy
                break
            else:
                if self.distanceTo(enemy) < minDistance:
                    minDistance = self.distanceTo(enemy)
                    target = enemy
    if target:
        return target
    
def commandHero():
    target = pickTarget()
    if target:
        while target.health > 0:
            if self.isReady("bash") and target.health > 116:
                self.bash(target)
            else:
                self.attack(target)
    else:
        moveForward()
        
while True:
    
    summonGriffin()
    commandArchers()
    commandSoldiers()
    commandGriffins()
    commandPaladins()
    commandHero()
    flag = self.findFlag("green")
    if  flag:
        self.pickUpFlag(flag)
        

 else:
        moveForward() #im pretty sure the error is here

Ok i tried taking it out but they just dont move at one point so…

Just a quick first question: why are you using self? And have you copied some older code because of the double comment at the start (one of which has been edited.)
If so, I’m afraid I’m going to have to ask you to write some of your own code.

If not, sorry for asking, but I just want to make sure…
Danny

Yes, i wasnt able to pass the level not even close to the end with my code, so i read all of the other codes in the forum and this was the best one, i tried fixing it a little even tying the jumpTo command but nothing can i get a little help?