The thing you need to keep in mind is that you will be fighting other heroes in this multiplayer level. While the original AI shows your hero, the actual fights won’t be the same hero oftentimes. For example, the list below shows multiple heroes that you will fight against. If you specify your code to just fight against Anya, you will lose a lot of battles.
The post below provides a pretty detailed line of code to ensure you find the opposite hero for the multiplayer regardless of what type.
Do you have all of this in a while True loop? Otherwise, you are only running through the code once. Also, I noticed that you have enemy in (), Python doesn’t need that. One other thing, in this case, I think it is better to have the index increment outside of your if statement (see below). Otherwise, if there isn’t an enemy, you will get stuck in an infinite loop.
while index < len(enemies):
enemy = enemies[index]
if enemy:
hero.attack(enemy)
index += 1
Hmm, not sure what to tell you, but the code works for me. I even copied straight from your post. What gear do you have? Is your hero dying?
Try something else for me. Add a hero.say like below.
if enemy:
hero.say(enemy.id) # add this line to see the names you are attacking
hero.attack(enemy)
By doing this you can see if your hero says more than one name. Also, the enemies are identified and it will show the second part enemy as the one currently indexed.
My solution to this error (‘loop’ breaks multiplayer code) is to do one command at the start (you can always do at least one), preferably an AOE (area of effect) spell like chain-lightning, or cleave. Then your soldiers have the advantage and win it for you. I use the silver bomb, but chain-lightning would work just as well.
Remember to put it at the top of your code so nothing else runs before it.
And @Deadpool198 knows best on this level!! This becomes critical when you are trying to rank up in the multiplayer ladder and playing against other people’s code. Some background info, a while back they used to use ‘loop’ instead of ‘while True’ and when they switched, all of the old codes that include ‘loop’ now create an error and can lock up your code as you saw.
What makes this highly problematic is that this is the Simple CPU that you start out playing against and don’t realize the problem is with the opposing code and not yours. As you see above, I brought this up on the post about the (‘loop’ breaking multiplayer code) hoping we can at least avoid this error in the training portion.
Another trick to look for is the red X under the enemy hero which let’s you know that their code has an error in it and may be disrupting yours.