Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Recognize and attack enemies when new enemies spawn


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???


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


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.


Click the code to see it.


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.


code is too blurry for me to see


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


i did still blurry (20 characters)


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.


I use this strategy a lot and it helps