Need help on The Two Flowers


# 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():
    enemy = hero.findNearestEnemy()
    hero.command(friend, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    coin = hero.findNearestItem()
    hero.move(coin.pos) 
peasant = hero.findByType("peasant")[0]

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

18%20PM
28%20PM

Make sure you read the error message carefully. It says “Line 10: ReferenceError: friend is not defined”
It’s quite self-explanatory. You haven’t defined friend. In case you don’t know how to define things it’s just when you set it as a variable. E.g. enemy = hero.findNearestEnemy()
Look back at your code, and see if you’ve defined friend.
Danny

1 Like