# Harrowland - hero dont move

**URL:** <https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790>\
**Category:** Level Help\
**Created:** [July 6, 2019, 3:17am UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790 "2019-07-06T03:17:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lollo58](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lollo58](https://discourse.codecombat.com/u/lollo58)\
**Post date:** [July 6, 2019, 3:17am UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/1 "2019-07-06T03:17:25Z")

</div>

Hy guy, i’ve another problem, in this level hero dont attack enemy… why? there is my code.

```python
enemies = hero.findEnemies()
index= 0
while index <len ( enemies):
    enemy = enemies[index]
    if enemy == "captain":
        if hero.canCast("chainlightning", enemy):
            hero.cast("chain-lightning", enemy)
        if enemy.health > 100:
            hero.attack(enemy)
        else:
            hero.attack(enemy)
    index = index+1

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [July 6, 2019, 7:39am UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/2 "2019-07-06T07:39:15Z")

</div>

I’m a bit confused. Is this all of your code? And not all heroes have the type “Captain”, only Anya.  
Could you tell me a bit more about your problem.  
🦁 🦁 🦁

---

<div class="post-metadata">

**Author:** ![lollo58](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lollo58](https://discourse.codecombat.com/u/lollo58)\
**Post date:** [July 7, 2019, 8:35am UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/3 "2019-07-07T08:35:26Z")

</div>

Hy Deadpool198…  
yes there is all my code… my hero is anya and in this level my opponent is an AI of anya…

[![](https://i.postimg.cc/jCK2F4kd/Cattura.jpg)](https://postimg.cc/jCK2F4kd)

When i start, my hero dont attack any enemies.

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 7, 2019, 3:29pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/4 "2019-07-07T15:29:05Z")

</div>

Put all of the code there inside a `while True` loop.

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [July 7, 2019, 7:37pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/5 "2019-07-07T19:37:39Z")

</div>

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.

![Harrowland%20characters](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/b/b3b38ee0bd3cb9c3dbcd3d9952e2499fd84bb96a.jpeg)

The post below provides a pretty detailed line of code to ensure you find the opposite hero for the multiplayer regardless of what type.

> [@Easiest way to select the enemy hero](https://discourse.codecombat.com/t/easiest-way-to-select-the-enemy-hero/3799/9):
>
> Enemy hero id can be "Hero Placeholder" or "Hero Placeholder 1". Examples for finding enemy hero (best to just add these to the top of the code, outside the main loop, and forget): # Python enemyHero = [e for e in self.findEnemies() if e.id in ["Hero Placeholder", "Hero Placeholder 1"]][0] // JavaScript var enemyHero = this.findEnemies().filter(function (e) { return e.id === 'Hero Placeholder' || e.id === 'Hero Placeholder 1'; })[0]; In mirror matches (Zero Sum, Ace of Coders) it’s easie…

---

<div class="post-metadata">

**Author:** ![lollo58](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lollo58](https://discourse.codecombat.com/u/lollo58)\
**Post date:** [July 8, 2019, 1:14pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/6 "2019-07-08T13:14:01Z")

</div>

Sorry, guy, but i’m confused…  
i try this simple code… but my hero attack only 1 enemy and stop.

```python
enemies= hero.findEnemies()
index = 0

while index < len(enemies):
    enemy = enemies[index]
    if (enemy):
        hero.attack(enemy)
        index += 1

```

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [July 8, 2019, 1:50pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/7 "2019-07-08T13:50:56Z")

</div>

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.

```python
while index < len(enemies):
    enemy = enemies[index]
    if enemy:
        hero.attack(enemy)
    index += 1

```

---

<div class="post-metadata">

**Author:** ![lollo58](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lollo58](https://discourse.codecombat.com/u/lollo58)\
**Post date:** [July 9, 2019, 3:18am UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/8 "2019-07-09T03:18:58Z")

</div>

Hy brooksy125, i change code and insert while true loop and move index increment, but hero only attack 1 enemy… sorry, but i dont understand…

```python
while True:
    enemies= hero.findEnemies()
    index = 0
    
    while index < len(enemies):
        enemy = enemies[index]
        if enemy:
            hero.attack(enemy)
        index += 1

```

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [July 9, 2019, 4:18am UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/9 "2019-07-09T04:18:12Z")

</div>

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.

```python
        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.  
 ![enemy%20Gary](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/5/5f04598744f3937abfea136f49d524464ab90448.jpeg) ![enemy%20Korra](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/8/8b05761b23e18ca1db49182165d8b9fd6f28a04a.jpeg) ![enemy%20Tina](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/9/9c990d410cdb98ef1da37072d7952a791e420ed9.jpeg)

---

<div class="post-metadata">

**Author:** ![lollo58](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lollo58](https://discourse.codecombat.com/u/lollo58)\
**Post date:** [July 9, 2019, 1:51pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/10 "2019-07-09T13:51:42Z")

</div>

This is my gear:  
[![](https://i.postimg.cc/VSQ23C6C/Cattura.jpg)](https://postimg.cc/VSQ23C6C)

my hero have all energy…

i try to rec my match.

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [July 9, 2019, 3:08pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/11 "2019-07-09T15:08:45Z")

</div>

Ok, I figured it out. I switched to the blue and played the simple enemy and they have bad code and it somehow stops your code.

Go back to the ladder (Scala), and click Play as Blue to pick a different opponent. I tried Easy against Giant Dad and it works now.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [July 9, 2019, 5:08pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/12 "2019-07-09T17:08:52Z")

</div>

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.  
🦁 🦁 🦁

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [July 9, 2019, 5:29pm UTC](https://discourse.codecombat.com/t/harrowland-hero-dont-move/18790/13 "2019-07-09T17:29:11Z")

</div>

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.
