# Collect 25 gold, and then tell Naria the total.
# Use break to stop collecting when totalGold >= 25.
totalGold = 0
coin = hero.findNearestItem()
# Pick up the coin.
# Add the coin's value to totalGold.
# Get its value with: coin.value
totalGold += coin.value
if totalGold >= 25:
# This breaks out of the loop to run code at the bottom.
# The loop ends, code after the loop will run.
# Done collecting gold!
# Go to Naria and say how much gold you collected.
When using hero.move the character gets first coin right in front, then immediately breaks the loop, goes to the bottom XY coordinates and says “27” if I use Hero.moveXY and the full written coin.pos.x / y then it works.
I’m trying to determine why hero.move breaks it and especially where it’s getting a random “27” variable from.Preformatted text
While troubleshooting the other part I also saw a reference about totalGold = totalGold + coin.value but then also found a video using the one from mine and the code works fine only changing the hero.move(coin.pos) to hero.moveXY(coin.pos.x, coin.pos.y)
It does work with that change, but I’m pulling out hair trying figure out why that breaks the loop and gives a high number when I’ve only collected a gold value of 3
So, @Manticore412, I tried running your code and I found the issue, but it’s not something that should normally make your code not work. The only difference between our codes though was the exact same thing @Lydia_Song said:
This is your difference:
This what mine changed:
It doesn’t make a lot of sense why this would change anything, because essentially they do the exact same thing. The only thing I can think of is that there might have be an issue internally, like when they were creating the level because they might have wanted you to only use hero.moveXY() in this level. Let me know if you have any further questions. Hope this helps! Grzmot