[SOLVED] Python - Sarven Sum / Hero not attacking enemies

Hello, I have managed to disable the fire-traps and I can reach the end of the level, so I will not spoil in and just post an excerpt of my code. But I don’t know why my hero simply ignores ennemies and goes straight for the last X.

#Above this line is my hero moving to the bone X and saying the answer to "Kitty

while True:
    enemy = hero.findNearestEnemy()
    item = hero.findNearestItem()
    if enemy:
        hero.attack(enemy)
    elif item:
        hero.moveXY(item.pos.x, item.pos.y)
    else:
        hero.moveXY(151, 118)

Thanks very much for your help, I have also try through hero.findEnemies() and incrementing but didn’t seem to work aswell.

I think it might be because when you first call hero.moveXY() there weren’t any enemies, and hero.moveXY can’t be interrupted by anything else, so even if enemies appear, the attacking code won’t run. You could fix this by using hero.move({“x”: 151, “y”: 118}).
Danny

2 Likes

Oh wow you’re right, I didn’t have access to that method cause I only had moveXY() boots. Thank you very much. I don’t fully understand how they’re different though.

EDIT : After reading the method and if anyone is interested, the move() tells the hero to only move one step which frees him/her after that step and repeats the loop, the moveXY() tells him/her to go to those coordinates no matter what

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.