# Python: Steelclaw Gap

**URL:** <https://discourse.codecombat.com/t/python-steelclaw-gap/26975>\
**Category:** Level Help\
**Created:** [January 24, 2021, 10:21pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975 "2021-01-24T22:21:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 24, 2021, 10:21pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/1 "2021-01-24T22:21:49Z")

</div>

It wants me to use a better target for “defend”

> **[CodeCombat - Coding games to learn Python and JavaScript](https://codecombat.com/play/level/steelclaw-gap)**
>
> Learn typed code through a programming game. Learn Python, JavaScript, and HTML as you solve puzzles and learn to make your own coding games and websites.

```python

# This level introduces the % operator, also known as the modulo operator.
# a % b returns the remainder of a divided by b
# This can be used to wrap around to the beginning of an array when an index might be greater than the length
defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
# You start with 360 gold to build a mixture of soldiers and archers.
# self.built is an array of the troops you have built, ever.
# Here we use "len(self.built) % len(summonTypes)" to wrap around the summonTypes array
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]
        # Use % to wrap around defendPoints based on friendIndex
        defendPoints % friend
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints)
while True:
    summonTroops()
    commandTroops()

```

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 24, 2021, 10:54pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/2 "2021-01-24T22:54:52Z")

</div>

I also have almost no idea what’s going on with the percent sign.

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 24, 2021, 11:12pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/3 "2021-01-24T23:12:45Z")

</div>

try doing this `defendPoint = defendPoints[i%len(defendPoints)]` instead of this

> [@CocoCharlie](#):
>
> `defendPoints % friend`

Otherwise your code is right

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 24, 2021, 11:16pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/4 "2021-01-24T23:16:11Z")

</div>

It still doesn’t like my command line.

> [@CocoCharlie](#):
>
> `hero.command(friend, "defend", defendPoints)`

```python
# This level introduces the % operator, also known as the modulo operator.
# a % b returns the remainder of a divided by b
# This can be used to wrap around to the beginning of an array when an index might be greater than the length
defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
# You start with 360 gold to build a mixture of soldiers and archers.
# self.built is an array of the troops you have built, ever.
# Here we use "len(self.built) % len(summonTypes)" to wrap around the summonTypes array
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]
        # Use % to wrap around defendPoints based on friendIndex
        defendPoints = defendPoints[i%len(defendPoints)
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints)
while True:
    summonTroops()
    commandTroops()

```

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 24, 2021, 11:44pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/5 "2021-01-24T23:44:34Z")

</div>

you have to do `hero.command(friend, "defend", defendPoint)` now it should work.

> [@CocoCharlie](#):
>
> ```python
> hero.command(friend, "defend", defendPoints)
> 
> ```

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 24, 2021, 11:45pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/6 "2021-01-24T23:45:03Z")

</div>

The only problem was that “s” in Points delete that and you are all good.

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 25, 2021, 12:23am UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/7 "2021-01-25T00:23:50Z")

</div>

yeah, still not working…

```python
# This level introduces the % operator, also known as the modulo operator.
# a % b returns the remainder of a divided by b
# This can be used to wrap around to the beginning of an array when an index might be greater than the length
defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
# You start with 360 gold to build a mixture of soldiers and archers.
# self.built is an array of the troops you have built, ever.
# Here we use "len(self.built) % len(summonTypes)" to wrap around the summonTypes array
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]
        # Use % to wrap around defendPoints based on friendIndex
        defendPoint = defendPoints[i%len(defendPoints)
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoint)
while True:
    summonTroops()
    commandTroops()

```

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [January 25, 2021, 3:27am UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/8 "2021-01-25T03:27:22Z")

</div>

@CocoCharlie you’re missing a closing square bracket `]` at the end of

```python
defendPoint = defendPoints[i%len(defendPoints)

```

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 25, 2021, 12:40pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/9 "2021-01-25T12:40:07Z")

</div>

You need to look at these things very carefully I told you how to do it here @CocoCharlie

> [@milton.jinich](#):
>
> defendPoint = defendPoints[i%len(defendPoints)]

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 25, 2021, 12:41pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/10 "2021-01-25T12:41:49Z")

</div>

This is solved now I believe(can you mark the post that helped you solve your problem CocoCharlie and change the title).

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [January 25, 2021, 3:03pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/11 "2021-01-25T15:03:24Z")

</div>

you don’t know if he solved it yet don’t rush him.

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 25, 2021, 3:08pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/12 "2021-01-25T15:08:04Z")

</div>

It worked! thanks guys! to honest I saw that bracket and deleted it lol.

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 25, 2021, 3:14pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/13 "2021-01-25T15:14:09Z")

</div>

lol i always forget to change the title.

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 25, 2021, 3:18pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/14 "2021-01-25T15:18:49Z")

</div>

Happens to me too. Did you get the Bonus @CocoCharlie?

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 25, 2021, 3:21pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/15 "2021-01-25T15:21:02Z")

</div>

ah, no. But I feel like you need to write a bunch of your own code, and my minds being blown enough already. 😉  
~Andrew

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 25, 2021, 3:24pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/16 "2021-01-25T15:24:12Z")

</div>

I actually told you based off how i got the bonus so you should have gotten it(if you did not submit it again).

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 25, 2021, 3:27pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/17 "2021-01-25T15:27:09Z")

</div>

An archer at the bottom-left corner dies at the end. 😥

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 25, 2021, 3:28pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/18 "2021-01-25T15:28:03Z")

</div>

submit again it should work I did it with the exact same code.

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [January 25, 2021, 3:35pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/19 "2021-01-25T15:35:24Z")

</div>

the soldiers get stuck behind the archers.

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [January 25, 2021, 3:36pm UTC](https://discourse.codecombat.com/t/python-steelclaw-gap/26975/20 "2021-01-25T15:36:38Z")

</div>

That is normal happened to me and I got the bonus submit until it works

[Next page](https://discourse.codecombat.com/t/python-steelclaw-gap/26975.md?page=2)
