The two flowers help please

# If the peasant is damaged, the flowers will shrink!

def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

# Define the function: commandSoldiers
def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    items = hero.findItems()
    nearestCoin = hero.findNearest(items)
    if nearestCoin:
        hero.move(nearestCoin.pos)
peasant = hero.findByType("peasant")[0]

while True:
    summonSoldiers()
    commandSoldiers()
    pickUpNearestCoin()

You haven’t stated what’s wrong but looking at your code I’m figuring that the soldiers aren’t attacking. Is this correct?

Edit:

Yes, I just ran your code. Soldier is not defined. Try defining friend first and then (after the for statement) using if friend.type == soldier.

You’re really close and the for statement should have friend as well, not soldier.

2 Likes