Attack enemies one by one


#1

in the level Cloudrip Brawl i want to attack the enemies one by one so i made this code but i keep getting infinite loop

here is my code

self.toggleFlowers(False)
loop:
    soldiers = self.findFriends()
    enemies = self.findEnemies()
    index=0
    enemy = enemies[index]
    if self.costOf("soldier")<self.gold:
        self.summon("soldier")
    else:
        coin = self.findNearest(self.findItems())
        self.move(coin.pos)
    if enemy:
        while len(enemies) > index  :
            for soldier in soldiers:
                self.command(soldier, "attack", enemy)
            index =+1

#2

The infinite loop is probably caused by the “index =+ 1”, it is supposed to be “index += 1”.


#3

i tried to change everything in the code but i never saw this :smiley: thanks for your help


#4

Glad to be of help. I’ve been there too.