Preferential treatment question

I can kill the throwers, but I just stand around after I have killed them.

I’m curious as to why this code doesn’t work.

enemies = self.findEnemies() 
enemyIndex = 0 
loop: 
    enemies = self.findEnemies() 
    enemyIndex = 0 
    while len(enemies) > enemyIndex:
        currentEnemy = enemies[enemyIndex]
        if currentEnemy.type == "thrower":
            self.attack(currentEnemy)
        enemyIndex = enemyIndex + 1

loop: 
    enemies = self.findNearest(self.findEnemies())
    for enemy in enemies:
        if enemy:
            self.attack(enemy)

or this code? I would think that simply copying the code and then making the enemy != to a thrower would make my hero kill the rest of the munchkins.

enemies = self.findEnemies() 
enemyIndex = 0 
loop: 
    enemies = self.findEnemies() 
    enemyIndex = 0 
    while len(enemies) > enemyIndex:
        currentEnemy = enemies[enemyIndex]
        if currentEnemy.type == "thrower":
            self.attack(currentEnemy)
        enemyIndex = enemyIndex + 1
enemies = self.findEnemies() 
enemyIndex = 0 
loop: 
    enemies = self.findEnemies() 
    enemyIndex = 0 
    while len(enemies) > enemyIndex:
        currentEnemy = enemies[enemyIndex]
        if currentEnemy.type != "thrower":
            self.attack(currentEnemy)
        enemyIndex = enemyIndex + 1``

The problem is that the loop command never terminates - maybe try using a while, or re-arrange your code without those loops

1 Like

Thanks Matt. That was the issue. Every time I ask a question on here it seems I’m doing something really silly wrong.