[SOLVED] Mad Maxer sells out Please Help

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:

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)

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

Try using one equal sign here

1 Like

Oh that makes sense! Thanks

1 Like

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. :partying_face: Also, welcome to the forum!


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