Use break to stop collecting when totalGold >= 25.
totalGold = 0
while True:
coin = hero.findNearestItem()
if coin and totalGold >= 25:
# 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
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
Use break to stop collecting when totalGold >= 25.
totalGold = 0
while True:
coin = hero.findNearestItem()
if coin and totalGold >= 25:
# 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
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
@darklord999, shouldn’t totalGold be less than 25? If your gold is 0, the code won’t run at all. Also, keeping totalGold += coin.value is fine, it still adds the coin’s value.
He is right it can’t be greater than 30 but he has to get 25 but if you have 24 and the nearest coin gives you 2 gold you get stuck and you code won’t run. But if you put that greater sign it is saying it okay to get 1 more coin to get 25 and less than 30.
Hey @darklord999!. I’m not going to provide any answers because it looks like multiple users have got it from here. But I would like to welcome you to the forum! Like @Lydia_Song said make sure to check out our rules located in her first post in the hyperlink.