[SOLVED]Grim determination (python)

Help

# 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!
    paladin = hero.findNeares(hero.findByType("paladin"))
if paladin.canCast("heal", hero):
    hero.command(paladin, "cast", "heal", hero)
    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()
    # Summon griffin riders!
hero.summon("griffin-rider")

It says paladin not defined.

Thereā€™s an indentation problem, but that might be to do with copying it in, and a typo on the hero.findNearest
But thatā€™s all I can see.

I donā€™t see an indentation but I got the typo

For starters, you need to follow the directions in the commandPaladin(paladin) function. You havenā€™t done any of that:

    # 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!

After that, you need to create the functions called for in the commandFriends() function. Just think about what the peasants should be doing or the griffin-riders should be doing (once you summon them).

@MunkeyShynes this is my new code, it says target not defined :confused:

# 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!
    lowestHealthPaladin()
    paladin.canCast("heal")
    hero.command(paladin, "cast", "heal", target)
    hero.command(paladin, "shield", target)
    hero.command(paladin, "attack", target)
    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()
    # Summon griffin riders!
hero.summon("griffin-rider")

Oh common, you didnā€™t put any effort into that at all. By now you already know to put an if conditional before casting spells.

if hero.canCast("spell"):
    hero.cast("spell", target)

You know how to do this. On the first one, you have to define target as the lowestHealthPaladin() so the one with the lowest health gets healed first.

`

22%20AM

1 Like

This is my code, and it says that ā€œhealā€ needs something to be cast upon.

# 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!
    target = lowestHealthPaladin()
    if paladin.canCast("heal"):
        hero.command(paladin, "cast", "heal", target)
    hero.command(paladin, "shield")
    hero.command(paladin, "attack", 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()
    # Summon griffin riders!
hero.summon("griffin-rider")

Hi @Code_Kid13.
This is where the error is coming from:

Firstly, look at the error message:

You have defined ā€˜targetā€™, but how are you sure it exists?
I would also recommend using an if, elif, else structure for this section of code as well.
Danny

I completed the level.