[Solved] Need Help With Hoarding Gold


#1

This is my code:

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.
        # Get its value with:  coin.value
        coin.value + totalGold = totalGold
        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.moveXY(59, 33)
hero.say(totalGold)

But my program won’t even work. Please help!


#2

Your code is right except for this line: coin.value + totalGold = totalGold
You need to definetotalGold as coin.value + totalGold not the other way round.


#3

Isn’t that what I am already doing?


#4

The variable name goes first, then the assignment. You put the definition (assignment) of the variable first. This is incorrect syntax.


#5

My Code Works Now. Thank you