I’m new to coding, and love learning, but I’m really struggling understanding:
a) how my code below functions. what are the mechanisms of iterating over arrays. what does that have to do with the ogres and bulls.
b) why my hero isn’t doing what I want him to do (attack the ogres)
Could someone please shed some light?
return #Commented out to stop infinite loop.
Use while loops to pick out the ogre
enemies = hero.findEnemies()
enemyIndex = 0
# Wrap this logic in a while loop to attack all enemies. # Find the array's length with: len(enemies) while enemyIndex < len(enemies): enemy = enemies[enemyIndex] # "!=" means "not equal to." if enemy.type != "sand-yak": # While the enemy's health is greater than 0, attack it! while enemy.health > 0: enemyIndex += 1 hero.attack(enemy) pass # Between waves, move back to the center.