Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

The Trials (Sarven desert one)

#1
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)
    
    
1 Like
#2

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.

1 Like
#3

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.

#4

thanks for the reply, will do that