# \[SOLVED\] Mixed Unit Tactics Python Help

**URL:** <https://discourse.codecombat.com/t/solved-mixed-unit-tactics-python-help/20240>\
**Category:** Level Help\
**Created:** [February 10, 2020, 8:07pm UTC](https://discourse.codecombat.com/t/solved-mixed-unit-tactics-python-help/20240 "2020-02-10T20:07:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Awesome000000000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/awesome000000000/32/11386_2.png) [@Awesome000000000](https://discourse.codecombat.com/u/Awesome000000000)\
**Post date:** [February 10, 2020, 8:07pm UTC](https://discourse.codecombat.com/t/solved-mixed-unit-tactics-python-help/20240/1 "2020-02-10T20:07:58Z")

</div>

Here is my code:

```python
# Practice using modulo to loop over an array

# Choose the mix and order of units you want to summon by populating this array:
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]

defendPoints = [{"x": 45, "y": 55},{"x": 45, "y": 45},{"x": 45, "y": 35},{"x": 45, "y": 25}]

def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)

def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        point = defendPoints[i % len(defendPoints)]
        hero.command(friend, "defend", point)

while True:
    friends = hero.findFriends()
    summonTroops()
    commandTroops()
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

```

Here is the error:  
 ![Screen Shot 2020-02-10 at 2.06.40 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/6/6dacb1335cd4cc8bb2f31831be394ea89ca8a79c.png)  
Can someone help?

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [February 10, 2020, 9:30pm UTC](https://discourse.codecombat.com/t/solved-mixed-unit-tactics-python-help/20240/2 "2020-02-10T21:30:14Z")

</div>

Hi. Command your troops types, not friends)

---

<div class="post-metadata">

**Author:** ![Awesome000000000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/awesome000000000/32/11386_2.png) [@Awesome000000000](https://discourse.codecombat.com/u/Awesome000000000)\
**Post date:** [February 11, 2020, 1:19pm UTC](https://discourse.codecombat.com/t/solved-mixed-unit-tactics-python-help/20240/3 "2020-02-11T13:19:11Z")

</div>

Thank you! I got it!

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [February 11, 2020, 2:43pm UTC](https://discourse.codecombat.com/t/solved-mixed-unit-tactics-python-help/20240/4 "2020-02-11T14:43:57Z")

</div>

You’re welcome)  
Good luck)
