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.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = self.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!
if friend and friend.type is "paladin":
enemies = friend.findEnemies()
enemy = friend.self.findNearest(enemies)
if lowestFriend:
self.command(paladin, "cast", "heal", lowestFriend)
if enemy:
self.command(paladin, "attack", enemy)
if paladin.health < 300:
self.command(paladin, "shield")
paladin.canCast("heal")
def commandFriends():
# Command your friends.
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)
elif friend.type == "paladin":
commandPaladin(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())
paladins = self.findByType("paladin", friends)
paladin = self.findNearest(paladins)
commandPaladin(paladin)
Hey guys, can I have some help?
Issues I’ve noticed:
- Inside the
commandPaladin
function, you have:
if lowestFriend:
self.command(paladin, "cast", "heal", 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.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = lowestHealthPaladin()
friends = self.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!
if friend and friend.type is "paladin":
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
if lowestFriend:
self.command(paladin, "cast", "heal", lowestFriend)
if enemy:
self.command(paladin, "attack", enemy)
if paladin.health < 300:
self.command(paladin, "shield")
paladin.canCast("heal")
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():
# Command your friends.
friends = self.findFriends()
for friend in friends:
if friend.type == "peasant":
commandPeasant(friend)
elif friend.type == "griffin-rider":
commandGriffin(friend)
elif friend.type == "paladin":
commandPaladin(paladin)
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())
paladins = self.findByType("paladin", friends)
paladin = self.findNearest(paladins)
commandPaladin(paladin)
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
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
![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/2/29eda36f8d1ce729f98198bfd16e0048cd5e39a4.png)
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){
hero.command(paladin, "cast", "heal", lowestFriend);
}
not work.
they didn’t heal each other.
so I did twick
if (paladin.health < 600 || paladin.health < 450){
hero.command(paladin, "cast", "heal", lowestFriend);
}
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")
self.command(paladin, "cast", "heal", lowestFriend)
lowestFriend находится в lowestHealthPaladin(paladin)
переместите lowestFriend=lowestHealthPaladin(paladin)
# Your goal is to protect Reynaldo
# Find the paladin with the lowest health.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = lowestHealthPaladin()
friends = self.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!
if friend and friend.type is "paladin":
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
if lowestFriend:
self.command(paladin, "cast", "heal", lowestFriend)
if enemy:
self.command(paladin, "attack", enemy)
if paladin.health < 300:
self.command(paladin, "shield")
paladin.canCast("heal")
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():
# Command your friends.
friends = self.findFriends()
for friend in friends:
if friend.type == "peasant":
commandPeasant(friend)
elif friend.type == "griffin-rider":
commandGriffin(friend)
elif friend.type == "paladin":
commandPaladin(paladin)
while True:
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())
paladins = self.findByType("paladin", friends)
paladin = self.findNearest(paladins)