Grim Determination, Plz help!


#1

I can’t figure out what the problem is! It looks good, and it kinda works, but I can’t survive!

This my code:

def lowestHealthPaladin():
friends = hero.findByType(“paladin”)
if len(friends) == 0:
return None
for friend in friends:
lowest = friends.pop()
if friend.health < lowest.health:
lowest = friend
return lowest

def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()

    if friend.type == 'paladin':
        if paladin.canCast('heal'):
            hero.command(friend, "cast",'heal', lowestHealthPaladin())
        else:
            hero.command(friend, "move", {'x': friend.pos.x + 5, 'y': friend.pos.y})
            if friend.pos.x > 80:
                hero.command(friend, "shield")
                if friend.health < friend.maxHealth/2:
                    hero.command(friend, "attack", enemy)
# 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!

#2

Seems like the format kinda broke…


#3

@TheRandomCoder, just asking, is that all of your code?


#4

Also, please format your code correctly according to the FAQ. Also, it is not (“paladin”), it is (‘paladin’).


#5

I only had one pre-made function that was empty and all the rest was made by myself. (it is true!)


#6

What about the commandFriends function? Where’s the rest of the code? It’s certain that you aren’t going to survive with just what you’ve got here.


#7

exactly. That is what I was trying to say.