Sarven Treasure, stuck in teleportation (first level, Python)


#1

Hi!
I’m trying to pass the first level of Sarven Treasure and this is the code I wrote:

loop:
    teleports = [{"x": 5.27, "y": 19.23}, {"x": 4.71, "y": 49.19}, {"x": 76.67, "y": 19.02}, {"x": 75.95, "y": 51.00}]
    teleport = hero.findNearest(teleports)
    coin = hero.findNearest(hero.findItems())
    enemy = hero.findNearest(hero.findEnemies())
    if enemy and hero.distanceTo(enemy) < 10:
        hero.move(teleport)
    elif coin:
        hero.move(coin.pos)

Everything goes fine until the ogre gets close to my hero - then my hero goes to the nearest X, gets teleported, goes back to the first X, gets teleported again and goes back again and so on until he gets killed.

What am I doing wrong?

Thanks!


#2

From what I understand here, the hero is around the enemy most of the time so the hero keeps moving to a teleporter, and since you can’t go to three areas at once, the hero will keep going back to the same teleporter, get teleported, and do it over again. I used flags for this level because I like to complete the level in real-time without having that many errors when I press submit for the level.


#3

thanks for the idea, i’ll try the flags!