# [SOLVED] Steelclaw Gap SOS

I don’t get anything!

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

After this put

``````posi = i % len(defendPoints)
``````

Then command the friend to defend the posi.

Andrei

It says there is no friend index

Andrei

Doesn’t work here is my code:

``````# 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
posi = i / len(defendPoints)
# Command your minion to defend the defendPoint
hero.command(friends, "move", posi)

while True:
summonTroops()
commandTroops()

``````

Here put “defend” instead of “move”.

Andrei

doesn’t work i only make 1 unit then it stops

code:

``````# 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
posi = i / len(defendPoints)
# Command your minion to defend the defendPoint
hero.command(friend, "defend", posi)

while True:
summonTroops()
commandTroops()

``````

Andrei

Check steelclaw gap yourself and then help me.
here is the link SteelClaw Gap

As Andrei mentioned…

I did it doesn’t work my avatar stays still

Ok, I see the problem. In this line:

``````        hero.command(friend, "defend", posi)
``````

replace ‘posi’ with: defendPoints[iposi]

You are attempting to use ‘posi’ as a coordinate, when it is actually a whole number. Instead, you need to use it as the index of the defendPoints array, which is where the needed coords are stored.

1 Like

You are wrong it isn’t iposi it is posi but with your help I succeded.

1 Like

lol…so I typoed! Still, congrats on completing the level

2 Likes

Thanks