Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Hoarding Gold (indentation error)


I’m having trouble with the Hoarding Gold level. I am sure my code is correct but the game says there is an indentation error on the code that was already there. The code is on lines 13 to 17. I removed the indentation like it tells me to, but
then the hero picks up all the coins instead of the amount I need.


Indentation error means you didn’t indent your code correctly. aka you pressed space or tab the wrong number of times. That happens also in an indent based coding language like python. But I can’t help you without your code so could you post the code with the indentation error please.


In those cases, I find it best to just delete the whole line up to the last character of the preceding line and start over. Because like FlowerChi said, somewhere in those ‘spaces’ is a tab or wrong space. Alternately you can go into settings and ‘show invisible characters’ and try and debug it that way, but deleting a line is just quick and easy. don’t just copy and paste, you will preserve your error


It looks like the issue resolved itself. The part where it says(pass if totalGold>+25:) was the part where it was having the indentation error. That part of the code was already there when I started the level. I guess it was a bug of some kind.

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.moveXY(coin.pos.x, coin.pos.y)
# Add the coin’s value to totalGold. (See the guide for more.)
# Get its value with: coin.value
totalGold += coin.value
if totalGold >= 25:
# >= means totalGold is greater than or equal to 25.
# This breaks out of the loop to run code at the bottom.

Done collecting gold!

hero.moveXY(58, 33)

Go to Naria and say how much gold you collected.

hero.say(“I have collected " + totalGold + " gold.”)


Huh, weird. Well I’m glad you have it working again!