# \[Solved\] Help on the Two Flowers

**URL:** <https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608>\
**Category:** Level Help\
**Created:** [August 23, 2020, 8:51pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608 "2020-08-23T20:51:21Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [August 23, 2020, 8:51pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/1 "2020-08-23T20:51:21Z")

</div>

```python
# 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.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [August 24, 2020, 8:35am UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/2 "2020-08-24T08:35:27Z")

</div>

> [@LunaFromTheMoon](#):
>
> `in hero.findFriends():`

Is Hector not your friend as well? I think he is, and he cannot be commanded – that’s your error. (hero.findByType("sold…))  
Danny

---

<div class="post-metadata">

**Author:** ![qjleny](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qjleny/32/24111_2.png) [@qjleny](https://discourse.codecombat.com/u/qjleny)\
**Post date:** [August 24, 2020, 12:39pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/4 "2020-08-24T12:39:06Z")

</div>

> [@LunaFromTheMoon](#):
>
> ```python
> def commandSoldiers():
> friends = hero.findFriends()
> for soldier in hero.findFriends():
> 
> ```

maybe you can do

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

```

and then command them to attack

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [August 25, 2020, 1:57pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/5 "2020-08-25T13:57:25Z")

</div>

My new code:

```python
# 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”

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 25, 2020, 2:06pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/6 "2020-08-25T14:06:50Z")

</div>

> [@LunaFromTheMoon](#):
>
> soldiers = hero.findByType(“soldier”)

get rid of this you dont need it and

```python
soldiers()

```

in line 9 needs to be changed to

```python
hero.findFriends()

```

does it work now?

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [August 25, 2020, 2:10pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/7 "2020-08-25T14:10:32Z")

</div>

No, it still says the same error “soldiers is not a function”

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 25, 2020, 2:11pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/8 "2020-08-25T14:11:12Z")

</div>

can i see your code?

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [August 25, 2020, 2:12pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/9 "2020-08-25T14:12:18Z")

</div>

```python
# 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()

```

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 25, 2020, 2:12pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/10 "2020-08-25T14:12:59Z")

</div>

get rid of line 8 does it work now?

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [August 25, 2020, 2:15pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/11 "2020-08-25T14:15:37Z")

</div>

No, I’m pretty sure you need that to define “soldiers”

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 25, 2020, 2:18pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/12 "2020-08-25T14:18:05Z")

</div>

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

```python
enemy = soldier.findNearestEnemy()

```

(sorry about that) in line 8 then you need to add

```python
if enemy:

```

```python
and soldier.type == "soldier"

```

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

---

<div class="post-metadata">

**Author:** ![MidnightWolf39](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/midnightwolf39/32/13309_2.png) [@MidnightWolf39](https://discourse.codecombat.com/u/MidnightWolf39)\
**Post date:** [August 25, 2020, 2:25pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/13 "2020-08-25T14:25:29Z")

</div>

> [@LunaFromTheMoon](#):
>
> `for soldier in soldiers():`

Delete the parenthesis.

---

<div class="post-metadata">

**Author:** ![DimaP](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dimap/32/10613_2.png) [@DimaP](https://discourse.codecombat.com/u/DimaP)\
**Post date:** [August 25, 2020, 2:26pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/14 "2020-08-25T14:26:06Z")

</div>

> [@LunaFromTheMoon](#):
>
> `soldiers()`

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

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 25, 2020, 2:27pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/15 "2020-08-25T14:27:04Z")

</div>

i needed the () to suceed

---

<div class="post-metadata">

**Author:** ![qjleny](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qjleny/32/24111_2.png) [@qjleny](https://discourse.codecombat.com/u/qjleny)\
**Post date:** [August 25, 2020, 7:34pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/16 "2020-08-25T19:34:46Z")

</div>

> [@LunaFromTheMoon](#):
>
> def commandSoldiers():  
> soldiers = hero.findByType(“soldier”)  
> for soldier in soldiers():  
> friends = hero.findFriends()  
> if enemy:  
> hero.command(soldier, “attack”, enemy)

should be

```python
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.

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [August 27, 2020, 4:50pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/17 "2020-08-27T16:50:01Z")

</div>

Thanks 😁. I got it

---

<div class="post-metadata">

**Author:** ![qjleny](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qjleny/32/24111_2.png) [@qjleny](https://discourse.codecombat.com/u/qjleny)\
**Post date:** [August 28, 2020, 10:11pm UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/18 "2020-08-28T22:11:11Z")

</div>

Hi and congratulations for finishing the level!!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [August 29, 2020, 10:11am UTC](https://discourse.codecombat.com/t/solved-help-on-the-two-flowers/23608/19 "2020-08-29T10:11:14Z")

</div>

Closed on August 29, 2020, 10:11am UTC

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