[Solved] Help with Mad Maxer sells out

Hi,
i’m having trouble with this one, my hero will collect two Gold coins but when he’s about to get the third one the coins disappears.

while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin:
            distance = hero.distanceTo(coin)
            if distance < minGoldDist and coin.value == 3:
                closestGold = coin
                minGoldDistance = closestGold
                pass
            coinIndex += 1
            pass
    if closestGold:
        hero.moveXY(closestGold.pos.x, closestGold.pos.y)
        pass

MadMaxerSellsOut01

You are assigning minGoldDistance the value of closestGold, which is a variable defined right above it that is assigned the value of coin. Coin is an object, not a distance. minGoldDistance should be assigned the value of distance, which is assigned hero.distanceTo(coin).

1 Like

Sorry that it took me 2 weeks to replay, But that didn’t help.

while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin:
            distance = hero.distanceTo(coin)
            if distance < minGoldDist and coin.value == 3:
                closestGold = coin
                minGoldDistance = hero.distanceTo(coin)
            coinIndex += 1
            pass
    if closestGold:
        hero.moveXY(closestGold.pos.x, closestGold.pos.y)
        pass

Your code is exactly the same. You didn’t make the change that I showed you. Make that change and it will work.

it’s not the same i changed minGoldDistance = closestGold to
minGoldDistance = hero.distanceTo(coin)

You already defined distance as hero.distanceTo(coin). You need to define minGoldDistance as distance.

1 Like

The same thing happens

while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin:
            distance = hero.distanceTo(coin)
            if distance < minGoldDist and coin.value == 3:
                closestGold = coin
                minGoldDistance = distance
                pass
            coinIndex += 1
            pass
    if closestGold:
        hero.moveXY(closestGold.pos.x, closestGold.pos.y)
        pass

or maybe because i’m Stupid? XD

Since you are using minGoldDist, replace minGoldDistance = distance with minGoldDist = distance Maybe this might work

1 Like

Thank you Chaboi_3000.

Oh my God…this is just awkward.

@Chaboi_3000 I didn’t catch that. Good one. :grinning:

2 Likes