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!
make lowestHealthPaladin a variable like weak = lowestHealthPaladin()
this might not fix it but sometimes (for some reason) that ends up making stuff work.
@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?
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?