# [Solved] 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():
friends = hero.findFriends()
for soldier in hero.findFriends():
enemy = soldier.findNearestEnemy()
soldiers = hero.findByType("soldier")
if enemy:
hero.command(soldier, "attack", enemy)

# This function commands your soldiers to attack their nearest enemy.
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
items = hero.findItems()
nearestCoin = hero.findNearest(items)
if nearestCoin:
hero.move(nearestCoin.pos)

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

Error Message: Line 14: ArgumentError: commandâ€™s argument minion should have type unit, but got object: Hector.

Is Hector not your friend as well? I think he is, and he cannot be commanded â€“ thatâ€™s your error. (hero.findByType("soldâ€¦))
Danny

1 Like

maybe you can do

``````def commandSoldiers():
soldiers = hero.findByType("soldier")
for soldier in soldiers:
``````

and then command them to attack

2 Likes

My new code:

``````# 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():
soldiers = hero.findByType("soldier")
for soldier in soldiers():
enemy = soldier.findNearestEnemy()
soldiers = hero.findByType("soldier")
if enemy:
hero.command(soldier, "attack", enemy)

# This function commands your soldiers to attack their nearest enemy.
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
items = hero.findItems()
nearestCoin = hero.findNearest(items)
if nearestCoin:
hero.move(nearestCoin.pos)

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

``````

It says â€śsoldiers is not a functionâ€ť

get rid of this you dont need it and

``````soldiers()
``````

in line 9 needs to be changed to

``````hero.findFriends()
``````

does it work now?

No, it still says the same error â€śsoldiers is not a functionâ€ť

``````# 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():
soldiers = hero.findByType("soldier")
for soldier in soldiers():
friends = hero.findFriends()
if enemy:
hero.command(soldier, "attack", enemy)

# This function commands your soldiers to attack their nearest enemy.
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
items = hero.findItems()
nearestCoin = hero.findNearest(items)
if nearestCoin:
hero.move(nearestCoin.pos)

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

``````

get rid of line 8 does it work now?

No, Iâ€™m pretty sure you need that to define â€śsoldiersâ€ť

ok im pretty sure i found the issue so you do need this

``````enemy = soldier.findNearestEnemy()
``````

``````if enemy:
``````
``````and soldier.type == "soldier"
``````

ok? edit: you need to combine the two on the same line does it work now?

Delete the parenthesis.

I think problem is here. Try to delete `()`.
Dima

1 Like

i needed the () to suceed

1 Like

should be

``````def commandSoldiers():
soldiers = hero.findByType("soldier")
for soldier in soldiers:
friends = hero.findFriends()
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", enemy)
``````

I did that and it worked fine.

2 Likes

Thanks . I got it

1 Like

Hi and congratulations for finishing the level!!!

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.