Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Shine Getter- Help

# To grab the most gold quickly, just go after gold coins.

while True:
    coins = hero.findItems()
    coinIndex = 0
    
    # Wrap this into a loop that iterates over all coins.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        # Gold coins are worth 3.
        if coin.value == 3:
            # Only pick up gold coins.
            hero.moveXY(coin.pos.x, coin.pos.y)
            coinIndex += 1
        pass
        

The yellow duck tells me the code’s too slow or has an infinite loop. Please help!

Think about the placement of this line, if not all the coins are gold, why only increment the index when it’s a gold coin? (An infinite loop means, as the name suggests, when the loop never ends, because coinIndex is never >= len(coins).
I hope this helps.