[Solved] Help with Mad Maxer sells out


#1

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

#2

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


#3

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

#4

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


#5

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


#6

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


#7

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


#8

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


#9

Thank you Chaboi_3000.

Oh my God…this is just awkward.


#10

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