The Two Flowers Level Help [Solved]

My error says that i am commanding hector, not a unit

# This level shows how to define your own functions.
# The code inside a function is not executed immediately. It's saved for later.
# This function has your hero collect the nearest coin.
def pickUpNearestCoin():
    items = hero.findItems()
    nearestCoin = hero.findNearest(items)
    if nearestCoin:
        hero.move(nearestCoin.pos)

# This function has your hero summon a soldier.
def summonSoldier():
    # If hero.gold is greater than the cost of the "soldier":
    if hero.gold > hero.costOf("soldier"):
        # Then summon a "soldier":
        hero.summon("soldier")
    pass


# This function commands your soldiers to attack their nearest enemy.
def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)

while True:
    enemy = hero.findNearestEnemy()
    
    # In your loop, you can "call" the functions defined above.
    # The following line causes the code inside the "pickUpNearestCoin" function to be executed.
    pickUpNearestCoin()
    # Call summonSoldier here
    summonSoldier()
    # Call commandSoldiers here
    commandSoldiers()
    if enemy and hero.gold > 18:
        if hero.isReady("bash"):
            hero.bash()
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        
        hero.attack(enemy)
    

how do you specify friends to a unit type?
or is there another solution?

Have you checked that all of your lines have no type errors?

there’s no type errors, excepting the one that i am requesting help for, which i dont think is technically a typo Screen Shot 2021-02-27 at 11.11.27 AM

and if you meant type like enemy.type yes i do

hmmmm. Have you tried to do this: friends = hero.findByType("peasant", hero.findFriends())

idk what the problem is, but do you have boss star 2?

no just level one boss star

Firstly, here try to use if hero.gold >= hero.costOf ("soldier")

then try to put this: friends = hero.findByType("peasant", hero.findFriends())
in the commandSoldiers function

yea, thats what I thought. I beat it with level one though could you post or updated code when you are done with what I just said?

ok i’ll try , i think it should work

welp same problem :pensive:

oh, okay. well can you post your updated code?

here you go

# This level shows how to define your own functions.
# The code inside a function is not executed immediately. It's saved for later.
# This function has your hero collect the nearest coin.
def pickUpNearestCoin():
    items = hero.findItems()
    nearestCoin = hero.findNearest(items)
    if nearestCoin:
        hero.move(nearestCoin.pos)

# This function has your hero summon a soldier.
def summonSoldier():
    # If hero.gold is greater than the cost of the "soldier":
    if hero.gold >= hero.costOf("soldier"):
        # Then summon a "soldier":
        hero.summon("soldier")
    pass


# This function commands your soldiers to attack their nearest enemy.
def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        friend = hero.findByType("peasant", hero.findFriends())
        if enemy:
            hero.command(soldier, "attack", enemy)

while True:
    enemy = hero.findNearestEnemy()
    
    # In your loop, you can "call" the functions defined above.
    # The following line causes the code inside the "pickUpNearestCoin" function to be executed.
    pickUpNearestCoin()
    # Call summonSoldier here
    summonSoldier()
    # Call commandSoldiers here
    commandSoldiers()
    if enemy and hero.gold > 18:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        
        hero.attack(enemy)
    

try to put this line at the very top of the commandSoldiers function and change the rest to this:

for friend in friends:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)

ok sure, but it says friends is not defined, so i changed your first line to that, but after that the same problem occured

hey i figured it out instead of peasant i put “soldier” but hey just arent fast enough

so the code is right, but he died anyway

did you change the rest to what I said after that?

sorry, he survives but loses too much health

yea it works, but i think the level itself should be nerfed

get rid of this you dont need it