Recognize and attack enemies when new enemies spawn


#1

I know I was told this before but now I don’t know how to fix my code so that my hero will recognize when new enemies spawn and stop proceeding to XY and instead resume the attack loop now that the condition has changed back to true. I found that this fixes it, hero.move({‘x’:151 , ‘y’: 118}), but is that the only way (What if I didn’t have boots that allow for that type of movement) or is there something else that I could have done???

code

while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            while enemy.health > 0:
                hero.attack(enemy)
        else:
            hero.moveXY(151, 118)

#2

what is your code? I cant see it because it is blurred out. I might be able to help if you show the code, and by the way, dont forget to do @Ironhead because I might not be available, so just remind me. What level are you on too? Reply to these questions first.


#3

Click the code to see it.


#4

If I remember correctly i have to have the hero move a bit then use an if enemy fight function then move a bit and fight again. I think that’s the only way that moveXY will work.


#5

code is too blurry for me to see


#6

Click on the code and it will show up more clearly.


#7

i did still blurry (20 characters)


#8

nevermind, @HeadMan, there aren’t many ways, but yours works very well. You could also use a flag and if enemy just click you hero’s location so he can start fighting.


#9

I use this strategy a lot and it helps