# Wishing well (python)

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

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)
‘’’

1 Like

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.

1 Like
``````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

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

1 Like

Wrong Number:
if goldAmount == 140:

1 Like

yeah i fixed that thanks though

1 Like

my character was greedy until I swapped him out with a girl

welcome to discourse @nothing_emty

the steel ring in COCO has a spelling problem i think

Electrocutes a target if within 20 ?

hi codebay2 how do you do move commands?

for what. with what. my explanation is moveXY or move

no with the no good soldiers