Steelclaw gap problem

It says fix your code on the self.command statement

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"]

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


def commandTroops():
    friends = self.findFriends()
    for friendIndex, friend in enumerate(friends):
        # Use % to wrap around defendPoints based on friendIndex
        pass
        # Command your minion to defend the defendPoint
        defendPoints=defendPoints[friendIndex % len(defendPoints) 
        self.command(friend, "defend", defendPoint)
loop:
    summonTroops()
    commandTroops()
1 Like

never mind i beat it

1 Like

@lundor5 can u please tell me what to do to fix it! Thx

1 Like

you need to figure it out for your self i dont give out free codes

1 Like

Lightside, people are not jumping to help you because it looks like you are trying to grab some code instead of working and writing your own.

Reload the level code, and work from there. Ask for help on a specific step and tell us why you think it should work.

The code posted here has also some syntax errors (grammar errors for programs). If you had worked on it you would have at least spotted the grammar errors.

2 Likes

Fine I will not do that anymore. Sorry @lundor5 and @AdrianCgw!!!

1 Like

Try some code, and if you have an error, or if it does not do what you want, post the code and tell us the different between what you expected and what your code does.

Format the code by surrounding it by 3 back-quotes (top-left on your keyboard):

code

1 Like

My code isnt getting the defendPoints, is something wrong or is it a bug? Yes, i know how old this topic is, but i need help.

# 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)):
        defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]
        friend = friends[i]
        friendIndex = 0
        # Use % to wrap around defendPoints based on friendIndex
        defPon = defendPoints[friendIndex % len(defendPoints)]
        # Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints)

while True:
    summonTroops()
    commandTroops()

i think this can help u

Your value friendIndex is not incrementing. and you are already using a value that increment. The value (i)