Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Steelclaw Gap - bug or wrong code?

hello everybody,
first at all, thanks for all yours contributes, it help me, a lot !!
now, I have a little problem, maybe it’s my code or it’s a bug… after few days of trying to find a solution… I don’t know !
here 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.costOf(type):

def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        # Use % to wrap around defendPoints based on friendIndex
        defPoint = defendPoints[friends[i] % len(defendPoints)]
        # Command your minion to defend the defendPoint
        hero.command(friend, 'defend', defPoint)

while True:

now, what happens… sometimes, I can’t open the level, too slow or an infinite-Loop…
when, I succeed to open it… I have to begin again the level.
when I click on “run” or “submit”, nothing happens, no enemy, no time (INFINITY : NaN)
when I click on “play” , my hero summon lot of units around him, and the bad guys arrived and my unit didn’t move and I loose.
and the code doesn’t finish to run…without any error message …

I don’t know if it’s enough clear… my poor english doesn’t help…

someone can help me ? please


Howdy and welcome to the forum!

Well, the good news is, it’s not a bug! :slight_smile: In your commandTroops function, you are defining defPoint with the modulo, then are using it in your hero.command statement.

Instead, try doing away with defPoint and use the modulo formula in the command statement itself.

I modified your code as mentioned and it completed just fine.

thank you for your answer
if I understand well, I have to put directly the value of the variable ‘defPoint’ : defendPoints[friends[i] % len(defendPoints)] in the hero.command ?

Close, yes.

defendPoints is an array, so adding a second array is mucking things up. Instead of using friends[i], use just the counter instead. The counter will indicate which element of defendPoints it should be referring to.

it’s done ! :grinning:
thank you very much !
I will try to not forget your advice !
Have a good day

1 Like