# Collect 25 gold, and then tell Naria the total.
# Use break to stop collecting when totalGold >= 25.
totalGold = 0
while True:
coin = hero.findNearestItem()
if coin:
# Pick up the coin.
hero.move(coin.pos)
# Add the coin's value to totalGold.
# Get its value with: coin.value
totalGold = totalGold + coin.value
pass
if totalGold >= 25:
# This breaks out of the loop to run code at the bottom.
# The loop ends, code after the loop will run.
break
# Done collecting gold!
hero.moveXY(58, 33)
# Go to Naria and say how much gold you collected.
hero.say(totalGold)
-
If I do this, my hero takes the first gold coin (3 values), and then tries to get to the next coins but, like 0.1 sec later, she turns her way straight to Naria and says ā25ā when the money I got is still only just 3.
-
and if I do this belowā¦
(only changed ātotalGold = totalGold + coin.valueā to ātotalGold = hero.gold + coin.valueā)
# Collect 25 gold, and then tell Naria the total.
# Use break to stop collecting when totalGold >= 25.
totalGold = 0
while True:
coin = hero.findNearestItem()
if coin:
# Pick up the coin.
hero.move(coin.pos)
# Add the coin's value to totalGold.
# Get its value with: coin.value
totalGold = hero.gold + coin.value
pass
if totalGold >= 25:
# This breaks out of the loop to run code at the bottom.
# The loop ends, code after the loop will run.
break
# Done collecting gold!
hero.moveXY(58, 33)
# Go to Naria and say how much gold you collected.
hero.say(totalGold)
then, my hero immediately stops when she has 24, and then goes to Naria and tells her 26.
Iāve checked a few posts but I couldnāt find the solution for this. Help me please.