Possible Brawl Glitch

I decided to see how far I could get in the brawls and for some reason if I don’t move back to a specific location after attacking my hero just won’t attack enemies after the first four or five. Should this be happening or is there a range of my weapon of 5-30m rather than just 30m and if that is correct then I would be glitching that too. I am using the rapid fire rifle.

This is roughly my code for most of the brawls on all the maps without having to use other abilities.

while True:
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy:
            hero.moveXY(x, y)

(MoveXY is my starting point).

I think you are seeing a weird problem that I sometimes run into.

Your list of enemies may contain an enemy that is dead and dead enemies still exist in some levels.

So, checking

if enemy:

may be true even if the enemy is dead, then if the hero tries to attack a dead enemy your program will hang up

I’ve worked around this problem by checking if the enemy exists AND its health is greater than zero. Like this:

if enemy and enemy.health > 0:

I think I learned this somewhere in the discourse but I can’t remember where. I’m pretty sure this is only an issue on the repeatable levels.

findNearestEnemy is searching only alive enemies. However, if enemy is dead after it had been found, then a variable can still contain a reference to the enemy object. It’s a normal practice in programming. It’s a good practice to “check” variables when your code is dynamical (like in CoCo) and running again and again.


That worked! Thanks!

1 Like

Thanks, that makes sense to me.

I guess what I mean by “weird problem” is that sometimes attacking something that is dead will make your hero say, “but its dead” and then she continues on with the rest of the code.

However, some other times if her attack target is dead she will still say, “but its dead”, and then the code will hang on that line and she will just stand there being beaten to death.

I think I have only seen the second way in the repeatable levels.