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()
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()
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
Just watch out for the indentation, it’s important in python:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
pickUpCoin()
Okay thanks for the information