Grim Determination has a bug about paladins

It doesn’t work.
bug: labeled
bug type: argument error: you need something to cast upon.

#sample
#paladin = hero.findNearest(hero.findByType("paladin"))
#if paladin.canCast("heal", hero):
#    hero.command(paladin, "cast", "heal", hero)

#starts here

# 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(p):
    # 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
    weak = lowestHealthPaladin()
    if p.canCast("heal", weak):
#bug
        hero.command(p, "cast", "heal", weak)
    else:
        hero.command(p, "shield")
    pass

#peasent commanded, not shown

#griffin command, not shown

def commandFriends():
    # Command your friends.
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            commandPeasant(friend)
        elif friend.type == "griffin-rider":
            commandGriffin(friend)
        elif friend.type == "paladin":
            commandPaladin(friend)
    #All commandable
    #boss star 3



while True:
    commandFriends()
    if hero.gold >= 50:
        hero.summon("griffin-rider")

What’s wrong? misspelled? Several times already!

Say lowestHealthPaladin returns None, which can happen if all paladins are at full health. Does p.canCast("heal", weak) make sense? You may need to check for the existence of weak first.

How do I find paladin health? Please tell me.
I tried using p.health, but it doesn’t work.

p.health will tell you the health of a paladin, provided it exists. Otherwise you’re trying to fetch the health of a non-existent paladin, which doesn’t make sense. You can see it used in the definition of lowestHealthPaladin.

To solve your original problem of not knowing whether the return value of lowestHealthPaladin exists or not, you should use an if, as so:

if p and p.canCast("heal", weak):

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic , which shows all essentials of this board! Thanks!
@Cheung_Wilbur can you send me a link to the level?