Help with Lurkers please? [SOLVED]


#1

Hey guys, sorry for constantly posting! I am trying to learn as much as I can and wrote my first line of code ever about 3 days ago! I am struggling with the Lurkers level currently and was wondering why my code was not working!

enemies = self.findEnemies()
enemyIndex = 0
    while enemyIndex < enemies.length:
        enemy = enemies[enemyIndex] 
            if enemy.type == 'shaman':
               while enemy.health > 0:
                    self.attack(enemy)
                    enemyIndex += 1

#2
  1. No need to indent the if statement under enemy =. Rule of thumb - no :, no indent for the line below (in python)
  2. The enemyIndex needs to be updated, whether or not the enemy.type == “shaman”. So, you need enemyIndex to line up with the enemy = statement as well. Currently, if you have any enemy out there other than a type shaman, the code will hang.

2a. Alternatively, do you have access to self.findByType() yet?
If you just want to kill enemy shaman, the first line could be corrected to:
enemies = self.findByType(“shaman”, self.findEnemies())


#3

Thanks a ton. I can’t believe I didn’t catch that!