New move() boots and sarven treasure

I am just getting my head around the move() method with my new boots. I am wondering how I can prevent myself from switching targets rapidly between the teleporter and the closest coin. It causes me to lose time collecting nothing. I feel like I need another variable or another if statement, but I am not sure how to make that work without ruining what I love about the move method… the ability to collect coins on my way to the teleporter.

loop:
    ogre = self.findNearest(self.findEnemies())
    closestCoin = self.findNearest(self.findItems())
    if closestCoin and ogre:
        coinDistance = self.distanceTo(closestCoin)
        ogreDistance = self.distanceTo(ogre)
        targetX = closestCoin.pos.x
        targetY = closestCoin.pos.y    
        myX = self.pos.x
        myY = self.pos.y
        ogreX = ogre.pos.x
        ogreY = ogre.pos.y
        if ogreDistance < 7:
            if myX > ogreX and myY > ogreY:
                self.move({"x":75, "y":50})
            elif myX > ogreX and myY <= ogreY:
                self.move({"x":75, "y":20})
            elif myX <= ogreX and myY > ogreY:
                self.move({"x":5,"y":50})
            elif myX <= ogreX and myY <= ogreY :
                self.move({"x":5,"y":20}) 
        elif closestCoin:
            self.move({"x": targetX,"y": targetY})      

easiest way would be to use moveXY when using the teleporter, then you won’t pick a new action until after you get there.

Using moveXY as Vlevo said seems a good idea. When the ogres are too close, you go strait to the teleporter.
Now If you still want to collect gems, you can imagine a kind of hysteresis.
If ogreDistance < 7, you set a variable like : teleporter = True;
If ogreDistance >12, teleporter = False.
And then you pick up gems only if teleporter = False.
if ogreDistance is in the middle, you continue to do what you were doing, it avoid to switch too fast from one task to another.

Just a simple idea, there is so much you can do…

I really want to avoid using moveXY because I seemed to be missing so many coins on my way to the teleporter. @Vettax your idea about a variable for the teleporter made me wonder what would happen if I adjust my coin retrieval to a limited distance if I am running to a portal… Like if the ogre gets within 7 then I will only pick up coins within a distance of 5 or so. It seems I could do a lot with that variable…

You can move() to coins until your distance to a teleporter is less than whatever and then you ignore coin code.

if distanceTo(teleporter or whatever it is defined as in your code) > 10:
    coin = self.findNearest(self.findItems())
    move(coin.pos)

If you’ll look closely, you’ll see the previous post was from March 11. This person is probably not still looking for help; if he were, he would have asked for it. Thank you for your contribution, but please make it where it will do good in the future.