Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Grim determination help 2

# 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!
    if paladin.canCast("heal"):
        target = lowestHealthPaladin()
        if target:
            hero.command(paladin, "cast", "heal", target)
    else:
	   hero.command(paladin, "shield", hero)
    pass

def commandFriends():
    # Command your friends.
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy()
    for friend in friends:
        if friend.type == "peasant":
            #commandPeasant(friend)
            item = friend.findNearestItem() 
            hero.command(friend, "move", item.pos)
            pass
        elif friend.type == "griffin-rider":
            #commandGriffin(friend)
            hero.command(friend, "attack", enemy)
            pass
        elif friend.type == "paladin":
            commandPaladin(friend)

while True:
    commandFriends()
    # Summon griffin riders!
    if hero.gold >= hero.costOf("griffin-riders"):
        hero.summon("griffin-rider")
    else:
        pass
        

I keep getting an error on line 49:
if hero.gold >= hero.costOf(“griffin-riders”):
It keeps saying the argument should have type object but got string. I can’t see what’s wrong with my code though?

Hi, look at these two statements:
hero.costOf(“griffin-riders”)
and
hero.summon(“griffin-rider”)
Can you see the difference?
To work out which one’s right, think how many griffin riders you’re summoning or checking the price of.
:lion: :lion: :lion:

Thanks! Feel so stupid missing that one!

This is very interesting ( and here it will obviously not run)

hero.command(paladin, "shield", hero) // the hero is far away

I tried hero.command(paladin, "shield", target ) in my code expecting an error but there was none!
Does this command make sense?
Edit:
No, this command doesn’t make sense - it must be hero.command(paladin, "shield")
But in python there must be an error message!!! Try this code:

def fp(a, b):
    print('a: ' + a)
    print('b: ' + b)
print('### python missing 1 argument ###') 
fp(1)
print('### adding 1 argument plus ###')
fp(1, 2, 3)

The output in the browser console is:
browser-console
and that is normal if the code was in java script but not for python.
Same code run in python console ( not in Code Combat ):
p1given p3given
I cannot say that’s a BUG, maybe this was the intention of the game designers, but count carefully the
number of arguments you’re feeding your function :slight_smile: