Enemy tag stuck on a dead enemy

@Neith, we are not allowed to give answers on the discourse, only help. If we we give answers, you won’t be learning and passing it yourself.

I couldn’t find any solution. I think when a target dies, it should disappear. But it doesn’t. And i dont know how to change a person from my “enemy” targets which is health -x. Normally it changes but when in shield it doesn’t. So, in my opinion, that’s a problem of the game. Thats why you dont know how to solute but try to say cool things like “make sure of that”. That’s funny, just dont reply if you couldn’t solute it. There is no any solution, but i appreciate you guys for making excuses.

How can i be more sure? How, just how, please let me know.

That’s very easy.Just do this if condition:

if enemy.health > 0:
   #your code

If you want an explanation of the problem itself, I assume the enemy does not get deleted from database of all enemies.Thus, it does not disappear.

Actually it would be a while loop not an if loop. So while the enemy’s health is greater than zero you would attack it.

Well then “sorry for trying to say cool things and not helping you” if your that sure its a game problem then report it to the staff.

2 Likes

yeah, you’re right.Thanks for correcting!

@Anonym Thanks but if you look these 2 pictures in the comment im replying, you can see that im using the code u said. But still my hero tries to activate the if condition even enemy.health is not greater than 0 and it says “But its dead!” So what do you think about it?

I will summon @Chaboi_3000 and @Deadpool198 since it’s still not working. And Neith, we are not saying cool things. We honestly can’t give you the solution- even if you’ve been stuck on this for awhile. I think you need to calm down a little and let the others help you.

1 Like

I’m just going to go off your starting code because I don’t want to read the topic and find out all the changes, if there are any, that you’ve made.
Please also post your code into the forum so I can copy and paste it, rather than posting a screenshot of it, because then I have to write it out myself to test it.
I’m afraid the real problem starts before the shield function. You haven’t defined your variables very well.

enemies = hero.findEnemies()
enemy = weakestenemy(enemy)

How come you’re using enemy in the brackets of weakestenemy() when you haven’t defined it yet? You’re trying to use the enemy variable in the very definition of the variable itself. That’s called recursion and I’m pretty sure it’s not what you were going for.
Then, inside the weakestenemy() function, you haven’t defined enemies. As I told you (admittedly quite recently), you have to redefine variables inside each function, or carry them over from the while True loop. You can’t just use your variables wherever you want unfortunately.
Same goes for the bash function.
There has been an error reported about bash() breaking code, but we can’t be sure that’s the problem yet because there are so many other problems that need to be fixed first.

2 Likes

First of all, if there is a known bug about breaking bash command, the problem is definitely that. And the same problem is with hero.shield(), i mentioned and showed with pictures.

My code was

def bash(enemy):
    if enemy and hero.isReady("bash"):
        enemy = weakestenemy(enemy)
        hero.bash(enemy)
        pass

def weakestenemy(enemy):
    enemyIndex = 0
    noob = None
    a = 999999
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if a > enemy.maxHealth and enemy.health > 0:
            a = enemy.maxHealth
            noob = enemy
        enemyIndex += 1
    return noob


while True:
    friends = hero.findFriends()
    if hero.time < 1:
        hero.wait(0.1)
    enemies = hero.findEnemies()
    enemy = weakestenemy(enemy)
    if enemy and enemy.type != "sand-yak":
        while enemy.health > 0:
            bash(enemy)
            hero.attack(enemy)
        while len(enemies) <= 3 and len(friends) >= 5:
            bash(enemy)
            hero.shield()

I’m sure that my enemy definements are well enough, i use them all the time. But when using bash or shield, sometimes and randomly my character stops.

For the bracket of weakestenemy(), actually its not weakestenemy(). I defined as weakestenemy(enemy) which means i carried my enemy definement. which why should work just like the my other topic how i solved. So, i defined as weakestenemy(x) and i wrote in the real code as weakestenemy(x). The result of this will be enemy, it does not matter if my variable is the same name with “x”.

There is no any problem when you remove the last one, try it:

while len(enemies) <= 3 and len(friends) >= 5:
            bash(enemy)
            hero.shield()

Note: character generally stops when this last while sentence being activated.

It just doesnt change “enemy” mark when bashing, it tries bash and bash and bash no matter what is if condition and what comes after and says "But its dead!"

When i was writing them i checked again, copied the codes and tried it but again when last “while” started, it didnt work as always. The character was starting to say but its dead and do nothing (it was like that from the beginning of the topic). But now, it changes the “enemy” mark and goes for the last enemy to bash and back to shield ! Thank god someone fixed it.

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