# Grim Determination

Hi guys, i need help on grim determination. There are no errors but it doesn’t work! Here is my code:

``````
# Find the paladin with the lowest health.
lowestHealth = 99999
lowestFriend = None
friends = self.findFriends()
for friend in friends:
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend

return lowestFriend

# And don't forget, they can attack, too!

if friend and friend.type is "paladin":
enemies = friend.findEnemies()
enemy = friend.self.findNearest(enemies)
if lowestFriend:
if enemy:

def commandFriends():
friends = self.findFriends()
for friend in friends:
if friend.type == "peasant":
def commandPeasant(friend):
coins = friend.findItems()
coin = friend.findNearest(coins)
if coin:
coinPosition = coin.pos
peasants = self.findByType("peasant", friends)
peasant = self.findNearest(peasants)
self.command(peasant, "move", coinPosition)
elif friend.type == "griffin-rider":
def commandGriffin(friend):
if friend and friend.type is "griffin-rider":
self.command(friend, "attack", enemy)

loop:
commandFriends()
# Summon griffin riders!
enemy = self.findNearest(self.findEnemies())
if enemy and self.gold >= self.costOf("griffin-rider"):
self.summon("griffin-rider")
friends = self.findFriends()
friend = self.findNearest(self.findFriends())
``````

Hey guys, can I have some help?

Issues I’ve noticed:

• Inside the `commandPaladin` function, you have:
``````        if lowestFriend:
``````

However, you did not define the `lowestFriend` variable. Add `lowestFriend = lowestHealthPaladin()` in the beginning of the `commandPaladin` function.

• Your `commandPeasant` and `commandGriffin` functions are defined inside the `commandFriends` function and are never called. Take a deep look at how the `commandPaladin` function is defined and called—the function is defined outside of any other function, and then it is called from inside the `commandFriends` function.

Hi guys i’m back and I still need help on the level. I don’t remember if I fixed any of the problems so if you are there @UltCombo can I have some help? Here is my code:

``````# Your goal is to protect Reynaldo

# Find the paladin with the lowest health.
lowestHealth = 99999
friends = self.findFriends()
for friend in friends:
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend

return lowestFriend

# And don't forget, they can attack, too!

if friend and friend.type is "paladin":
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
if lowestFriend:
if enemy:

def commandPeasant(friend):
coins = friend.findItems()
coin = friend.findNearest(coins)
if coin:
coinPosition = coin.pos
peasants = self.findByType("peasant", friends)
peasant = self.findNearest(peasants)
self.command(peasant, "move", coinPosition)
def commandGriffin(friend):
if friend and friend.type is "griffin-rider":
self.command(friend, "attack", enemy)
def commandFriends():
friends = self.findFriends()
for friend in friends:
if friend.type == "peasant":
commandPeasant(friend)
elif friend.type == "griffin-rider":
commandGriffin(friend)

loop:
commandFriends()
# Summon griffin riders!
enemy = self.findNearest(self.findEnemies())
if enemy and self.gold >= self.costOf("griffin-rider"):
self.summon("griffin-rider")
friends = self.findFriends()
friend = self.findNearest(self.findFriends())
``````

The error that it is showing is: ReferenceError: lowestFriend is not defined.

You’ve put `lowestFriend = lowestHealthPaladin()` inside the `lowestHealthPaladin` function itself, when it should be inside the `commandPaladin` function.

Your `paladin.canCast("heal")` is misplaced, it does nothing where you have placed it. It should be part of the `if` statement, e.g.: `if lowestFriend and paladin.canCast("heal"):`

Also note your function parameter names. The `commandPaladin` receives a parameter named `paladin`, but you are calling it `friend` in a few places inside the function. Likewise, in your `loop`, you are trying to pass a variable `paladin` which doesn’t exist there, the variable is named `friend` in your loop.

In your `commandPeasant` function, you should command the peasant that you have received as parameter to that function, you don’t need to find more peasants inside the function.

Another thing, you don’t need to check the type of the friend inside the `commandGriffin` and `commandPaladin` functions, you are already checking the type of the units before you pass them to these functions.

Note: these are just some problems that I’ve noticed with a quick glance. Perhaps you will have better luck if you re-check the previous levels to recap what you were doing and then restart this level by pressing the “Reload” button in the top-right of the game screen.

1 Like

Thanks for the help man! I did it!

1 Like

Congratz!

THANKS!!

I keep on getting so many email from codecombat discourse and its kinda
annoying

Hey, @Newmany.

Those emails should contain a link to unsubscribe from them. Alternatively, you can open your Account Settings page and uncheck the “send me an email” options that you don’t want. You likely want to disable the “Mailing list mode” as that sends you an email for every post made in the forum.

Also need help -
my peasants don’t want to continue collect coins!
They stuck after collecting a firs one.
I tried minor changes

So I find my mistake -
I summoned griffins without checking my gold, and it’s slow down a cycle
`hero.summon("griffin-rider");`

so I changed and now it works

``````    if (hero.gold>=hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
}
``````

BUT guys!!! =)))
if I kill the Warlock, it’s blow up everything!!
haha))

how then I shoud survive? heal and shield?

code

``````if(lowestFriend){
}
``````

not work.
they didn’t heal each other.

so I did twick

``````
}
``````

and they start work out)

I press PLAY and have success even with bonus, hit SUBMIT and lose three times in a row 'till I get my “lucky” seed

and screen from my struggling - guess how to get it?

``````а если paladin не может cast("heal")
if lowestFriend:

``````
``````if paladin.canCast("heal")
``````
``````
``````

``````
``````
``````# Your goal is to protect Reynaldo

# Find the paladin with the lowest health.
lowestHealth = 99999
friends = self.findFriends()
for friend in friends:
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend

return lowestFriend

# And don't forget, they can attack, too!

if friend and friend.type is "paladin":
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
if lowestFriend:
if enemy:

def commandPeasant(friend):
coins = friend.findItems()
coin = friend.findNearest(coins)
if coin:
coinPosition = coin.pos
peasants = self.findByType("peasant", friends)
peasant = self.findNearest(peasants)
self.command(peasant, "move", coinPosition)
def commandGriffin(friend):
if friend and friend.type is "griffin-rider":
self.command(friend, "attack", enemy)
def commandFriends():
friends = self.findFriends()
for friend in friends:
if friend.type == "peasant":
commandPeasant(friend)
elif friend.type == "griffin-rider":
commandGriffin(friend)