[HELP] Summit's Gate

My hero (Ritic the Cold) gets past the first wave of ogres and all my other units die, but then he goes in between both beam towers and dies. Sometimes he gets past but then he gets killed by either a skeleton or a warlock. Here is my code:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
while True:
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("green")
    friends = hero.findFriends()
    if flag:
        hero.pickUpFlag(flag)
    elif enemy and enemy.type == "tower":
        hero.attack(enemy)
    elif enemy:
        for friend in friends:
            hero.command(friend, "attack", enemy)
        hero.attack(enemy)

Somebody please help me.

1 Like

Now I changed my code to this:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
while True:
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("green")
    friends = hero.findFriends()
    paladins = hero.findByType("paladin")
    if flag:
        hero.pickUpFlag(flag)
    elif enemy and enemy.type == "tower":
        hero.attack(enemy)
    elif enemy:
        for friend in friends:
            hero.command(friend, "attack", enemy)
        hero.attack(enemy)
    if hero.health < 1355:
        for paladin in paladins:
            hero.command(paladin, "cast", "heal", hero)

and I get this error:

1 Like

What if the current paladin is unable to heal?

In each of my army of units there are two paladins, so each of them should be able to cast heal twice but instead I get that error when my paladins try to cast heal.

1 Like

I put an if statement:

while True:
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("green")
    friends = hero.findFriends()
    paladins = hero.findByType("paladin")
    if flag:
        hero.pickUpFlag(flag)
    elif enemy and enemy.type == "tower":
        hero.attack(enemy)
    elif enemy:
        for friend in friends:
            hero.command(friend, "attack", enemy)
        hero.attack(enemy)
    if hero.health < 1355:
        for paladin in paladins:
            if paladin.canCast("heal"):
                hero.command(paladin, "cast", "heal", hero)
1 Like

That is what I was implying…I’d also recommend an else, having him defend the hero if he can’t cast.

I added the else statement

1 Like

This is my new code:

while True:
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("green")
    soldiers = hero.findByType("soldier")
    archers = hero.findByType("archer")
    paladins = hero.findByType("paladin")
    if flag:
        hero.pickUpFlag(flag)
    elif enemy and enemy.type == "tower":
        hero.attack(enemy)
    elif enemy:
        for soldier in soldiers:
            hero.command(soldier, "attack", enemy)
        for archer in archers:
            hero.command(archer, "attack", enemy)
        for paladin in paladins:
            if hero.health < 1355:
                for paladin in paladins:
                    if paladin.canCast("heal"):
                        hero.command(paladin, "cast", "heal", hero)
                    else:
                        hero.command(paladin, "defend", hero)
        hero.attack(enemy)

1 Like

this is my code:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
while True:
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("green")
    friends = hero.findFriends()
    paladins = hero.findByType("paladin")
    if enemy and enemy.type == "warlock":
        hero.attack(enemy)
        for friend in friends:
            if friend and friend.type != "paladin":
                hero.command(friend, "attack", enemy)
    else:
        if flag:
            hero.pickUpFlag(flag)
        elif enemy and enemy.type == "tower":
            hero.attack(enemy)
        elif enemy:
            for friend in friends:
                if friend and friend.type != "paladin":
                    hero.command(friend, "attack", enemy)
            for paladin in paladins:
                if hero.health < 1355:
                    for paladin in paladins:
                        if paladin.canCast("heal"):
                            hero.command(paladin, "cast", "heal", hero)
                        elif enemy:
                            for paldin in paladins:
                                hero.command(paladin, "attack", enemy)
            hero.attack(enemy)

It keeps showing the error in post #3:

1 Like

What keeps happening is that when all of my paladins die, I get that error

1 Like

I added an if and solved the problem and the level. I made the same mistake twice, thanks for correcting it @dedreous .

3 Likes