Need help on A Fine MInt


#1

My code.

def pickUpCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)

while True:

hero.attack(enemy)
pickUpCoin()

#2

Instead of putting this:

while True:
     hero.attack(enemy)
     pickUpCoin()

Do this:

while True:
     enemy = hero.findNearestEnemy()
          if enemy:
              hero.attack(enemy)
     pickUpCoin()

So that it actually checks repeatedly if there is an enemy or not


#3

Just watch out for the indentation, it’s important in python:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    pickUpCoin()

#4

Okay thanks for the information