# Steelclaw gap, stuck! really frustrated!

I keep getting stuck! I don’t understand!!!

So I can see what’s wrong with it.
Danny

# 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”]

# 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

``````    # Command your minion to defend the defendPoint
``````

while True:
summonTroops()
commandTroops()

this is the code I was given

Make sure you put ``` at the start of your code on a new line, and at the end of your code also on a new line.
Danny

ok
do you use python?
that’s what I use.

I can do both, I just need to see your code formatted (with the indents at the start of each line) so I can paste it into my level screen and test it.

I don’t understand modulo
I think I need to complete other levels

Danny

was that right???
I don’t know.
I have not used the forum before

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

# Command your minion to defend the defendPoint

while True:
summonTroops()
commandTroops()

``````

You nailed it that time! I personally think the final two comments should be rearranged, but that’s me:

``````        # Command your minion to defend the defendPoint
# Use % to wrap around defendPoints based on friendIndex
``````

So, the goal is to command your minion to defend point X of 4. Modulo will allow you to cycle through the defendPoint array. So, you need to write the command statement to match what the comment is stating.

1st part-what to do = command
2nd part-who = minion = friend[i] = friend
3rd part-to do what = ‘defend’
4th part-defend what = defendpoint[ X]…now, how would you define 'X"? Instead of a variable, it would be better to use the actual definition code instead.

thx
(20 characters long)

I % 4 was the answer