while True: enemy = hero.findNearestEnemy() flag = hero.findFlag() item = hero.findNearestItem() #this will follow the flag if flag: hero.moveXY(flag.pos.x, flag.pos.y) #this will find and attack an enemy if enemy: hero.attack(enemy) #this will find and pickup item item = hero.findNearestItem() if item == "mushroom": hero.moveXY(item.pos.x,item.pos.y)
i got this issue with my code. although technically it works i get a problem collecting the mushrooms.
having the code structured like this, the hero ping-pongs between killing an enemy and picking up a mushroom.
Thanks in advance for any tips.
My tip for you is to turn this:
into this so the flag is prioritized.
elif enemy: hero.attack(enemy)
I recommend removing the
if item part because you can use flags to handle the mushroom collecting.
thanks for the reply, will do that