[solved] Kelbintaph Crusaders targeting problem

while True:
    friends = hero.findFriends()
    for friend in friends:
        witch = friend.findNearest(friend.findByType('witch'))
        ogre = friend.findNearest(friend.findByType('ogre'))
        if friend.id is "paladin":
            paladin = friend
        if friend.id is "archer":
            archer = friend
        if friend.id is "soldier":
            soldier = friend
        
        if witch:
            target = witch
        elif ogre:
            target = ogre
        else:
            target = friend.findNearestEnemy()
        if witch:
            hero.command(archer, "attack", witch)
        if paladin:
            hero.command(paladin, "defend", archer)
        if ogre:
            hero.command(soldier, "attack", ogre)

These are lines 20 to 43 of my code, and my archers only target the things near them. I’m trying to do different tactics for my units, but they keep targeting only the nearest. Why are they doing this?

witch = friend.findNearest(friend.findByType('witch')) 
ogre = friend.findNearest(friend.findByType('ogre'))
#         it says NEAREST

Well, your troops are finding the ogres closest to them, as you stated.

But I also tried to make them target the witch by making the witch a seperate enemy

if witch:
            hero.command(archer, "attack", witch)

Oh! I think I misunderstood the question.

I’m not sure whether this is the root of the problem, but friend.id is the friends name, e.g. Carol etc…
You should use .type.
Danny

thanks ill take note of that

i changed some stuff along with what you said. I don’t know it it’s a different problem now but they still target the nearest (I assume)

while True:
    friends = hero.findFriends()
    for friend in friends:
        witch = friend.findNearest(friend.findByType('witch'))
        ogre = friend.findNearest(friend.findByType('ogre'))
        if friend.type is "paladin":
            paladin = friend
        if friend.type is "archer":
            archer = friend
        if friend.type is "soldier":
            soldier = friend
        
        if witch:
            target = witch
        elif ogre:
            target = ogre
        else:
            target = friend.findNearestEnemy()
        hero.command(soldier, "attack", target)
        hero.command(paladin, "defend", archer)
        hero.command(archer, "attack", target)

as it turned out the code i left out was the reason why i wasn’t getting it done. I had my hero jump into the catapults, then shield a bunch, but it was outside the while true loop. I fixed it now.