# Grim Determination(python)

**URL:** <https://discourse.codecombat.com/t/grim-determination-python/28289>\
**Category:** Level Help\
**Created:** [April 5, 2021, 4:53pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289 "2021-04-05T16:53:04Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [April 5, 2021, 4:53pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/1 "2021-04-05T16:53:04Z")

</div>

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!

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

```

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [April 5, 2021, 4:56pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/2 "2021-04-05T16:56:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thebagel](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thebagel/32/22241_2.png) [@thebagel](https://discourse.codecombat.com/u/thebagel)\
**Post date:** [April 5, 2021, 5:00pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/3 "2021-04-05T17:00:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [April 5, 2021, 5:04pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/4 "2021-04-05T17:04:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![\_Codemaster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_codemaster/32/26944_2.png) [@\_Codemaster](https://discourse.codecombat.com/u/_Codemaster)\
**Post date:** [April 5, 2021, 11:25pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/5 "2021-04-05T23:25:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [April 18, 2021, 4:45am UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/6 "2021-04-18T04:45:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![21-Nikkil\_Amarnath](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/21-nikkil_amarnath/32/22016_2.png) [@21-Nikkil\_Amarnath](https://discourse.codecombat.com/u/21-Nikkil_Amarnath)\
**Post date:** [April 18, 2021, 4:59am UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/7 "2021-04-18T04:59:53Z")

</div>

try this @CocoCharlie

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

```

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [April 18, 2021, 5:27am UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/8 "2021-04-18T05:27:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![21-Nikkil\_Amarnath](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/21-nikkil_amarnath/32/22016_2.png) [@21-Nikkil\_Amarnath](https://discourse.codecombat.com/u/21-Nikkil_Amarnath)\
**Post date:** [April 18, 2021, 5:41am UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/9 "2021-04-18T05:41:10Z")

</div>

Do you have the sense stone

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [April 18, 2021, 8:37am UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/10 "2021-04-18T08:37:01Z")

</div>

> [@CocoCharlie](#):
>
> `hero.command(paladin, "shield", enemy)`

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 )

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [April 18, 2021, 8:47am UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/11 "2021-04-18T08:47:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RenegadePenguin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renegadepenguin/32/21959_2.png) [@RenegadePenguin](https://discourse.codecombat.com/u/RenegadePenguin)\
**Post date:** [April 18, 2021, 3:04pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/12 "2021-04-18T15:04:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RenegadePenguin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renegadepenguin/32/21959_2.png) [@RenegadePenguin](https://discourse.codecombat.com/u/RenegadePenguin)\
**Post date:** [April 18, 2021, 3:31pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/13 "2021-04-18T15:31:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [April 18, 2021, 8:38pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/14 "2021-04-18T20:38:30Z")

</div>

@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’.

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [April 18, 2021, 9:36pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/15 "2021-04-18T21:36:11Z")

</div>

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.:

> [@CocoCharlie](#):
>
> ```python
> 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!
> 
> ```

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

> [@CocoCharlie](#):
>
> I changed `enemy` to `self`

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

As for healing

> [@CocoCharlie](#):
>
> ```python
> if paladin.canCast("heal"):
> hero.command(paladin, "cast","heal", lowestHealthPaladin())
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [April 18, 2021, 10:12pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/16 "2021-04-18T22:12:10Z")

</div>

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

```python
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!

```python
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?

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [April 18, 2021, 10:25pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/17 "2021-04-18T22:25:27Z")

</div>

> [@xython](#):
>
> the hidden while true loop in:

Nice catch)

> [@xython](#):
>
> Where are the 2020 -2021 Regulars?

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

---

<div class="post-metadata">

**Author:** ![Anonym](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anonym/32/47546_2.png) [@Anonym](https://discourse.codecombat.com/u/Anonym)\
**Post date:** [April 20, 2021, 2:51pm UTC](https://discourse.codecombat.com/t/grim-determination-python/28289/18 "2021-04-20T14:51:56Z")

</div>

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