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.

@Deadpool198 @jka2706 @Alexbrand I summon you! (sry I need help)

try this @CocoCharlie

def commandPaladin(paladin):
    if (paladin.canCast("heal")):
        target = lowestHealthPaladin()
        if target:
            hero.command(paladin, "cast", "heal", target)

yeah that didn’t work, It still says I need a target. All that did was add a variable for the same code.

Do you have the sense stone

I don’t check the whole code, but at first sight I definitely don’t think you need to protect your enemy by your paladin shield )

In javascript, as in CoCo python additional function parameters are ignored.

Might it be related to the fact that you’re calling commandPaladin(paladin) in the while true loop when paladin isn’t defined?

Also, if everyone’s at full health, then there will be no lowesthealthpaladin to target.

1 Like

@21-Nikkil_Amarnath I have best sense stone, watch, gun, glasses (although I’m not using the twilight ones), flag, belt, gloves, and boots. I also have all the rings. I try to have as many abilities at my disposal as I can.

@Alexbrand I changed enemy to self. I was trying to shield against the enemy.

@RenegadePenguin I tried to define paladin, but It didn’t do anything. and my paladins get attacked, so they’re just not healing. and the error is ‘no target’.

I’m sorry, don’t want to offend you… But the whole code looks like a strange salad… (Well except lowestHealthPaladin() function - it’s copied from previous levels as far as I remember and it’s ok). Besides I’m not good programmer. But I doubt if you understand the meaning of lines you wrote(
F.e.:

You define commandPaladin(paladin) function, then put commandPaladin(friend) in commandFriends() function. And in while True: loop you use commandFriends() function and put commandPaladin(paladin) function right after that.
Also hero=self, so I think you don’t reallly need paladins to shield your hero

hero.command(paladin, "shield") would be enough.

As for healing

There is lack of conditions in it. Like what if lowestHealthPaladin() would have 100% of health?

1 Like

I don’t remember ever seeing that : the hidden while true loop in:

def commandPaladin(paladin):
    while True:
        enemy = hero.findNearestEnemy()
      # code
      # no way to escape from the loop

Commanding the same units ( in this case paladins) in two places in the main loop is No, No!

while True:
    commandFriends() # you're commanding paladins using commandPaladin function
                     # elif friend.type == "paladin":
                     #       commandPaladin(friend)
                     # and then again
    commandPaladin(paladin)

And why same people reply for the same questions for years? Where are the 2020 -2021 Regulars?

1 Like

Nice catch)

Chattering about nachos, huh?) Or they leave this place already.

2020-2021 regulars cannot check all the topics in one second.

2 Likes