So I have been stuck on the lurkers level for to many hours to count. I have tried and lost so much code tinkering with it. So I would love to catch some advice and figure out where my code goes wrong.
enemies = self.findEnemies()
enemyIndex = 0
"#"Wrap this section in a while loop to iterate over all enemies.
while enemyIndex < 3:
enemy = enemies[enemyIndex]
if enemy.type == 'shaman':
while enemy.health > 0:
self.attack(enemy)
else
enemyIndex +=1
enemies = self.findEnemies()
enemyIndex = 0
while enemyIndex <= 3
# Wrap this section in a while loop to iterate over all enemies.
enemy = enemies[enemyIndex]
if enemy.type == 'shaman':
while enemy.health > 0:
self.attack(enemy)
enemyIndex = enemyIndex + 1
on the line while enemyIndex <= 3, the program says “unexpected token”. I would love to know what I am doing wrong!
So I gave it another fair shot tonight. Two of us actually. Anyways were both still lost.
Code in current format
enemies = self.findEnemies()
enemyIndex = 0
#Wrap this section in a while loop to iterate over all enemies.
while enemyIndex <= 3:
enemy = enemies[enemyIndex]
if enemy.type == 'shaman':
enemyIndex = enemyIndex + 1
while enemy.health > 0:
self.attack(enemy)
You’re incrementing enemyIndex at the wrong place.
Try the following:
enemies = self.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
enemyIndex += 1
#Note: You have to increase the index in every case, even if it's no shaman.
if enemy.type == 'shaman':
#gently 'awaken' him
# findEnemies returns a list of all your enemies.
# Only attack shamans. Don't attack yaks!
enemies = self.findEnemies()
enemyIndex = 0
# Wrap this section in a while loop to iterate over all enemies.
while enemyIndex < 6:
enemy = enemies[enemyIndex]
if enemy.type == 'shaman':
pos = enemy.pos
x = pos.x
y = pos.y
self.moveXY(x, y)
self.say("Wake up")
enemyIndex += 1
while enemy.health > 0:
self.attack(enemy)
else:
enemyIndex += 1
I need help with this too I can’t seem to get the right answer for the end. here is what I have
// findEnemies returns a list of all your enemies.
// Only attack shamans. Don’t attack yaks!
var enemies = this.findEnemies();
var enemyIndex = 0;
// Wrap this section in a while loop to iterate over all enemies.
// While the enemyIndex is less than the length of enemies
while(enemyIndex < enemies.length) {
var enemy = enemies[enemyIndex];
if (enemy.type == ‘shaman’) {
while (enemy.health > 0) {
this.attack(enemy);
}
}
}