# \[SOLVED\] Mad Maxer sells out Please Help

**URL:** <https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733>\
**Category:** Level Help\
**Created:** [January 13, 2023, 6:06am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733 "2023-01-13T06:06:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ephemera](https://avatars.discourse-cdn.com/v4/letter/e/8baadc/32.png) [@Ephemera](https://discourse.codecombat.com/u/Ephemera)\
**Post date:** [January 13, 2023, 6:06am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733/1 "2023-01-13T06:06:14Z")

</div>

Hi everyone, I’ve been stuck at this level for days and cannot figure out why. My hero is not going for the closest coin but always going for the second closest so I cannot get enough coins before time runs out.  
Please check out my code below:

```python
while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    # Find the closest coin that is gold.
    # Remember that gold coins have a value of 3.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin and coin.value == 3 and hero.distanceTo(coin) < minGoldDist:
            closestGold = coin
            minGoldDist == hero.distanceTo(closestGold)
        coinIndex += 1
    if closestGold:
        #Now go to the closest gold coin and get it!
        hero.moveXY(closestGold.pos.x, closestGold.pos.y)
        pass

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 13, 2023, 8:23am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733/2 "2023-01-13T08:23:01Z")

</div>

Hi @Ephemera and welcome to the discourse! Thank you for formatting your code.

> [@Ephemera](#):
>
> `minGoldDist == hero.distanceTo`

Try using one equal sign here

---

<div class="post-metadata">

**Author:** ![Ephemera](https://avatars.discourse-cdn.com/v4/letter/e/8baadc/32.png) [@Ephemera](https://discourse.codecombat.com/u/Ephemera)\
**Post date:** [January 13, 2023, 10:17am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733/3 "2023-01-13T10:17:39Z")

</div>

Oh that makes sense! Thanks

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 13, 2023, 11:28am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733/4 "2023-01-13T11:28:15Z")

</div>

If someone solves your level help post, please click the [Solution] button next to that person’s post so that others will know you do not need anymore help. 🥳 Also, welcome to the forum!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [January 13, 2023, 11:28pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-sells-out-please-help/34733/5 "2023-01-13T23:28:31Z")

</div>

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