# Mad Maxer Help!

**URL:** <https://discourse.codecombat.com/t/mad-maxer-help/15976>\
**Category:** Level Help\
**Created:** [September 19, 2018, 7:50pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976 "2018-09-19T19:50:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 19, 2018, 7:50pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976/1 "2018-09-19T19:50:29Z")

</div>

Can anyone me with this

```python
while True:
    farthest = None
    maxDistance = 0
    enemyIndex = 0
    enemies = hero.findEnemies()
    
    # Look at all the enemies to figure out which one is farthest away.
    while enemyIndex < len(enemies):
        target = enemies[enemyIndex]
        enemyIndex += 1
    
    # Is this enemy farther than the farthest we've seen so far?
    distance = hero.distanceTo(target)
    if distance > maxDistance:
        maxDistance = distance
        farthest = target
    
    if farthest:
        # Take out the farthest enemy!
        # Keep attacking the enemy while its health is greater than 0.
        while enemy.health > 0:
            hero.attack(enemy)
        pass

```

My hero doesn’t do anything

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [September 19, 2018, 9:34pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976/2 "2018-09-19T21:34:40Z")

</div>

You have 2 errors.  
You only iterate trough enemies array without defining the farthest within the loop. Indent your code properly.  
The enemy variable is void. You never initialized it.

But the level can be passed even without correcting the first error and I don’t know why ?!  
Without correcting the indentation farthest = enemies [len(enemies) - 1]  
so the code can be written as:

```python
while True:
    enemies = hero.findEnemies()
    enemy = enemies[len(enemies)-1]
    if enemy:
        while enemy.health > 0:
            hero.attack(enemy)

```

And this has passed several times. Does it mean that in the enemies array from enemies = hero.findEnemies() the last element is always the farthest?  
/PS: I will delete code if needed/

---

<div class="post-metadata">

**Author:** ![Sharknado](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sharknado/32/9124_2.png) [@Sharknado](https://discourse.codecombat.com/u/Sharknado)\
**Post date:** [September 19, 2018, 9:54pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976/3 "2018-09-19T21:54:00Z")

</div>

thank you for your help

---

<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:** [September 20, 2018, 5:10pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976/4 "2018-09-20T17:10:57Z")

</div>

Please could you not put topics where you need help with your code in the adventurer category which is for level making. uncategorized is the right category for that.  
Thanks. 😁

---

<div class="post-metadata">

**Author:** ![Finnian\_Weiland](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/finnian_weiland/32/10976_2.png) [@Finnian\_Weiland](https://discourse.codecombat.com/u/Finnian_Weiland)\
**Post date:** [November 7, 2019, 3:41pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976/5 "2019-11-07T15:41:14Z")

</div>

help plz 🥺

---

<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:** [November 7, 2019, 5:23pm UTC](https://discourse.codecombat.com/t/mad-maxer-help/15976/6 "2019-11-07T17:23:29Z")

</div>

If you need help with your code, please could you post it, formatted. (instructions on formatting: [How to Post Your Code With Radiant, Harmonious Formatting](https://discourse.codecombat.com/t/how-to-post-your-code-with-radiant-harmonious-formatting/1484))  
And I will help you work it out.  
Danny
