Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Rich Forager flag problems


Hello! new to the forums. When I place a flag down in the Rich Forager level, my hero moves to the flag but then he doesn’t attack anything. He just stands at the flag and lets himself get beaten down. Is it a problem in my code or what? I’m not sure if it’s a bug or i’m doing something wrong.

    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()

    if flag:
        fpos = flag.pos
        fx = fpos.x
        fy = fpos.y
        self.moveXY(fx, fy)
    elif enemy:
    elif item:
        ipos = item.pos
        ix = ipos.x
        iy = ipos.y
        self.moveXY(ix, iy)


Quicktip: you should try to pick up that flag or else it is not going to execute your elif code


Yep, Sam_Sam_Sam is correct. You are telling him to run to any flag on the map, as long as you don’t pick up the flag it will just stay there because your hero is following the first command - go to a flag.

I think you can just say:

if flag:
elif ....

This is because the pickUpFlag code will cause you to move to the flag automatically.


I think you could also reorder your code so that attacking an enemy takes precedent over moving to (and picking up) the flag. I’ve learned that the hard way - nothing’s worse that watching your hero get killed while running to a flag!