meee
1
I am for some reason not collecting coins
code:
def heroAttack():
enemy = hero.findNearestEnemy()
if enemy:
if hero.distanceTo(enemy) < 15:
if enemy.type == “munchkin”:
hero.attack(enemy)
return “enemy”
def heroCollect():
item = hero.findNearestItem()
if item:
if hero.distanceTo(item) < 15:
if item == “coin”:
hero.moveXY(item.pos)
return “item”
while True:
enemy = hero.findNearestEnemy()
if enemy:
heroAttack()
item = hero.findNearestItem()
if item:
heroCollect()
Return is not needed in this code.
Try this:
def heroAttack():
enemy = hero.findNearestEnemy()
if enemy:
if hero.distanceTo(enemy) < 15:
if enemy.type == "munchkin":
hero.attack(enemy)
def heroCollect():
item = hero.findNearestItem()
if item:
if hero.distanceTo(item) < 15:
if item.type == "coin":
hero.moveXY(item.pos.x, item.pos.y)
while True:
enemy = hero.findNearestEnemy()
if enemy:
heroAttack()
item = hero.findNearestItem()
if item:
heroCollect()
And welcome to the discourse!
1 Like
meee
5
Thank you so much. I owe you my life.
1 Like