This is your code with some additional comments:
coins = self.findItems() # use hero instead of self, don't be sure they are the same thing
coinIndex = 0
hero.say('len(coins) = ' + len(coins)) # picture added below
# while len(coins) < 3: # this will never be true
while # add code here to compare coinIndex with len(coins)
# Wrap this into a loop that iterates over all coins.
coin = coins[coinIndex]
# Gold coins are worth 3.
if coin.value == 3:
# Only pick up gold coins.
# pos=coin.pos # comment this line pos isn't same as pos in x = coin.pos.x or coin.pos.y
# it's a new variable you don't use
x = coin.pos.x
y = coin.pos.y
# increment somewhere in the second while loop coinIndex to iterate through all the coins
I added hero.say('len(coins) = ’ + len(coins)) for debug and this is the picture:
So you must add a condition after while to compare coinIndex with len(coins)