Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Grim Determination(python)

I’ve been putting this level off for a while, but I decided to do it again. But I already got stuck trying to command the paladin to “heal”. It’s saying I need a target, even though I have lowestHealthPaladin() in there.
Can someone help? thanks!

# Your goal is to protect Reynaldo
# Find the paladin with the lowest health.
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend
def commandPaladin(paladin):
    # Heal the paladin with the lowest health using lowestHealthPaladin()
    # You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    # Paladins can also shield: command(paladin, "shield")
    # And don't forget, they can attack, too!
    while True:
        enemy = hero.findNearestEnemy()
        if paladin.canCast("heal"):
            hero.command(paladin, "cast","heal", lowestHealthPaladin())
        else:
            hero.command(paladin, "shield", enemy)
    pass
def commandFriends():
    # Command your friends.
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            #commandPeasant(friend)
            pass
        elif friend.type == "griffin-rider":
            #commandGriffin(friend)
            pass
        elif friend.type == "paladin":
            commandPaladin(friend)
while True:
    commandFriends()
    commandPaladin(paladin)
    # Summon griffin riders!

And I know I need to code the rest of it still, I just got stuck on the heal part.

Idk what the prob… maybe you can’t call a function as a unit? maybe try making lowestHealthPaladin() as a variable???

That would be the same thing, @thebagel. and thankfully, it says I need a target, not that I have to use a unit.

make lowestHealthPaladin a variable like weak = lowestHealthPaladin()
this might not fix it but sometimes (for some reason) that ends up making stuff work.