while True:
enemies = hero.findEnemies()
# enemyIndex is used to iterate the enemies array.
enemyIndex = 0
# While enemyIndex is less than len(enemies)
while enemyIndex < len(enemies):
# Attack the enemy at enemyIndex
enemy = enemies[enemyIndex]
hero.attack(enemy)
# Increase enemyIndex by one.
enemyIndex += 1
coins = hero.findItems
# coinIndex is used to iterate the coins array.
coinIndex = 0
while coinIndex < len(coins):
# Get a coin from the coins array using coinIndex
coin = coinIndex
# Collect that coin.
hero.moveXY(coin.pos.x, coin.pos.y)
# Increase coinIndex by one.
coinIndex += 1
Please post your code properly formatted…we need to be sure that the proper indentations are being used, as this is also part of the code syntax. You can learn how to do this here: [Essentials] How To Post/Format Your Code Correctly
One detail I can see that needs correcting is how you assigned the coin variable value, review how the enemy variable was declared above.
Was there an error shown? If so, always provide those details to help others debug. Also giving a short description of what is happening (even when it is not what you want) may help too especially later with longer code.
# Wait for ogres, defeat them and collect gold.
while True:
enemies = hero.findEnemies()
# enemyIndex is used to iterate the enemies array.
enemyIndex = 0
# While enemyIndex is less than len(enemies)
while enemyIndex < len(enemies):
# Attack the enemy at enemyIndex
enemy = enemies[enemyIndex]
hero.attack(enemy)
# Increase enemyIndex by one.
enemyIndex += 1
coins = hero.findItems
# coinIndex is used to iterate the coins array.
coinIndex = 0
while coinIndex < len(coins):
# Get a coin from the coins array using coinIndex
coin = coinIndex
# Collect that coin.
hero.moveXY(coin.pos.x, coin.pos.y)
# Increase coinIndex by one.
coinIndex += 1