enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.type == 'shaman':
while enemy.health > 0:
hero.attack(enemy)
enemyindex = enemyindex + 1
My hero does nothing!!
you have enemyIndex twice
My code changed but it does not work.
enemyIndex = 0
if enemy.type == 'shaman':
enemies = hero.findEnemies()
while enemy.health > 0:
hero.attack(enemy)
enemyIndex += 1
enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
if enemy.type == 'shaman':
while enemy.health > 0:
hero.attack(enemy)
enemyindex = enemyindex + 1
Thatās a good thing⦠bruh
reset your code back to what it was
I am going off what my code is
This never assigns, it only readsā¦
Click on ācomment out my codeā twice and then it should load, and I know your mistake
What Moonwatcher said. Comment out your code twice. Then here are some things I noticed.
enemyIndex = 0
if enemy.type == 'shaman': #At this point in the code, enemy is not defined. You'll need to define it. Maybe a for-loop or a while-loop.
enemies = hero.findEnemies() #enemies isn't used in this conditional. You don't need this line.
while enemy.health > 0: #Again, enemy is not defined.
hero.attack(enemy) #Same enemy thing
enemyIndex += 1
#Actually, this whole part of this code is a duplicate of below.
enemies = hero.findEnemies()
enemyIndex = 0 #enemyIndex is already defined. You normally want to stay away from defining things twice.
while enemyIndex < len(enemies):
#you need to add an enemy variable here (enemy = enemies[enemyIndex]).
if enemy.type == 'shaman':
while enemy.health > 0:
hero.attack(enemy)
enemyindex = enemyindex + 1
You forgot to add the enemy thing on the lines in the while loop, and enemyindex and the end needs to have a capital i⦠and preferably use +=
Please mark the post that was the solution as the solution, not just yours :/