i am having an issue with eh level wishing well. My character only goes and collects about 20 coins and then stands there saying Non statis. my code is as follows
‘’’
less = “Nimis”
more = “Non satis”
requiredGold = 104

This function calculates the sum of coin values.

def sumCoinValues(coins):
i = 0
total = 0
while i < len(coins):
total += coins[i].value
i += 1
return total

while True:
items = hero.findItems()
goldAmount = sumCoinValues(items)
if len(items) != 0:
# If there is not enough gold, then say “Non satis”.
if goldAmount < 104:
hero.say(“non satis”)
if goldAmount >104:
hero.say(“Nimis”)
if goldAmount == 104:
coins = hero.findItems()
coinIndex = 0
nearest = coin
nearestDistance = 9999
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
if distance < nearestDistance:
nearest = coin
nearestDistance = distance
if nearest:
hero.moveXY(nearest.pos.x, nearest.pos.y)
‘’’

Why do you need an additional code to find the nearest coin? hero.findNearest(coins) can make it simpler.
You are trying to collect only coins which are closer than the fisrt in the list. You can use nested while true and collect coins while they are exist.

less = "Nimis"
more = "Non satis"
requiredGold = 104
# This function calculates the sum of coin values.
def sumCoinValues(coins):
i = 0
total = 0
while i < len(coins):
total += coins[i].value
i += 1
return total
while True:
items = hero.findItems()
goldAmount = sumCoinValues(items)
if len(items) != 0:
# If there is not enough gold, then say "Non satis".
if goldAmount < 104:
hero.say("non satis")
if goldAmount > 104:
hero.say("Nimis")
if goldAmount == 140:
while True:
coins = hero.findItems()
coinIndex = 0
nearest = coin
nearestDistance = 9999
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
if distance < nearestDistance:
nearest = coin
nearestDistance = distance
if nearest:
hero.moveXY(nearest.pos.x, nearest.pos.y)

my code does not seem to e working can some one tell me why its not working