Summit's Gate seems to have a bug

The level seems to produce random errors regarding functions.
It says hero has no method findFriends for example. It would also not accept hero.toggleFlowers(True) for the same reason at the beginning of the code.

here is my code so far:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
hero.toggleFlowers(True)
def lowestHealth():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def commandPaladin(paladin):
    weakFriend = lowestHealth()
    enemy = paladin.findNearestEnemy()
    if weakFriend and paladin.canCast("heal", weakFriend): 
        hero.command(paladin, "cast", "heal", weakFriend) 
    elif paladin and paladin.health <200:
        hero.command(paladin, "shield", paladin)
    else:
        hero.command(paladin, "attack", enemy)
    pass

def commandArcher(archer):
    thrower = hero.findByType("catapult")
    enemy = archer.findNearest(enemies)
    for friend in friends:
        if thrower:
            hero.command(archer, "attack", catapult)
        else:
            hero.command(archer, "attack", enemy)

def commandSoldier(soldier):
    for friend in friends:
        hero.command(friend, "attack", enemy)

def hero():
    if enemy and hero.isReady("cleave"):
        hero.cleave(enemy)
    elif enemy:
        hero.attack(enemy)
    elif hero.pos.x < 100:
        hero.attack({'x':101,'y':36})
    elif hero.pos.x < 150:
        hero.attack({'x':159,'y':36})
    elif hero.pos.x < 270:
        hero.attack({'x':288,'y':36})

def commandFriends():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            commandArcher(friend)
            pass
        elif friend.type == "Soldier":
            commandSoldier(friend)
            pass
        elif friend.type == "paladin":
            commandPaladin(friend)

while True:
    commandFriends()
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

2 Likes

Please, can you post screenshot with your equipment.
Dima

2 Likes

sure

1 Like

Try:

friends = hero.findFriends()
if friends:
    for friend in friends:
        if friend and friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

I think you should write:
if weakFriend and paladin.canCast("heal"):

I dont think, that you should write “paladin” after shield.

Maybe elif enemy:?

I think you should remove “for”. Also, “thrower” is array, “catapult” and “enemies” are undefined. Where is if enemy:?

What is “enemy”? It’s undefined. And maybe hero.command(soldier,"attack",enemy), and you don’t need “for”?

Again “enemy” is undefined. And I don’t think, that you can attack position.

if friends:? if friend:?

Do you mean “soldier”?

Where is hero() function?
And I don’t think, that you can pass this level with your equipment. I think you need better sword and helmet.
Dima

1 Like

My code is still work in progress, but thanks for too many explanations…
My question was primarily - why does this cause an error?

friends = hero.findFriends()
2 Likes

In what function is this error? And why do you need hero.toggleFlowers(True)?
Dima

2 Likes

In the commandFriends() function.

I don’t need it at all, this was just to show that some functions seem to cause errors randomly.

Thanks for your help

2 Likes

I don’t know why does this cause an error, but try to write if friends:, it can work, because sometimes it says an error, that doesn’t exist, instead of true error.
Dima

1 Like

still the same error (with or without the flowers…)

1 Like

to @DimaP: hero.findEnemies() Quiz

1 Like

And??? (20 chars)
Dima

1 Like

@Farmerama, when I changed what I said in Summit's Gate seems to have a bug, this bug disappeared. Try to do what I said, and then you won’t have this bug.
Dima

1 Like
friends = hero.findFriends()
if friends:# if friends will be True or False if there are no friends?
3 Likes

The problem was here. Try to write, for example controlHero().
Dima

1 Like