Sarven Treasure Python Teleport Issue

while True:
    enemy = hero.findNearestEnemy()
    enemies = hero.findEnemies()
    item = hero.findNearestItem()
    items = hero.findItems()
    itemDist = hero.distanceTo(item)
    
    
    
    #find nearest enemy(s) move to closest teleporter if distance less than 10m
    if enemy and hero.distanceTo(enemy) < 10:
        hero.moveXY(20, 20)
        closestTeleport = closest_teleport() #closestTeleport, move = closest_teleport
        hero.moveXY(closestTeleport[0], closestTeleport[1])
        #hero.move(move)
    elif item:
        hero.moveXY(item.pos.x, item.pos.y) #find nearest coin, move to coin
def closest_teleport():
    
    teleportA = [5, 50] 
    teleportB = [6, 19]
    teleportC = [76, 51]
    teleportD = [76, 19]
    distanceToA = distance_from_heros_position(teleportA[0], teleportA[1])
    #distanceToA = distance_between_points(teleportA[0], teleportA[1], hero.pos.x, hero.pos.y)
    distanceToB = distance_from_heros_position(teleportB[0], teleportB[1])
    distanceToC = distance_from_heros_position(teleportC[0], teleportC[1])
    distanceToD = distance_from_heros_position(teleportD[0], teleportD[1])
    if distanceToA < distanceToB and distanceToA < distanceToC and distanceToA < distanceToD:
        return teleportA#[0], teleportA[1])
    elif distanceToB < distanceToA and distanceToB < distanceToC and distanceToB < distanceToD:
        return teleportB#, {"x" : 5, "y" : 18} 
    elif distanceToC < distanceToA and distanceToC < distanceToB and distanceToC < distanceToD:
        return teleportC
    elif distanceToD < distanceToA and distanceToD < distanceToB and distanceToD < distanceToC:
        return teleportD
def distance_from_heros_position(a, b) :
    return distance_between_points(a, b, hero.pos.x, hero.pos.y)
def distance_between_points(a, b, c, d) :
    return ((a - c)**2)**0.5 + (((b - d)**2)** 0.5

So, I have my hero walking tot he nearest teleport when enemies come within 10m. The problem I am having is the hero never*( in one iteration before the time out occurs he actually does) reaches the exact starting point of the teleporter, so he attempts to get there over and over. I was wondering if there was any way to hero.moveXY(just outside of teleport range) and then follow up with a hero.move(into the teleporter), or possibly a different solution??

the hero.moveXY(20, 20) was used just to try to debug my teleportB

can you give me the all the code so i can possibly repeat the same thing.

that is all the code right there. I commented out some things I was experimenting with. another user dmed me suggesting I implement the hero.findNearest() and make the coordinates an object. below is some example code he provided, though I would like to get my implementation working somehow.

teleports = [{"x": 5, "y": 50},
             {"x": 6, "y": 19},
             # next teleport point,
             # last teleport point
          ]          
while True:
    coin = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 10:
        hero.move(hero.findNearest(teleports))
    elif coin:
        hero.move(coin.pos)

the only thing I see is a typo line 10 of my original post where i comment out a different assignment.it should read:

# , move = closest_teleport()