ok. well it does work, but it creates an infinite loop that does nothing right?
Understanding that we need to have indents in the code for it to be included in the loop, how would you change your current code to check for having only 30 coins ?
ok. well it does work, but it creates an infinite loop that does nothing right?
Understanding that we need to have indents in the code for it to be included in the loop, how would you change your current code to check for having only 30 coins ?
Break
stops the code and we would use this when we don’t want to repeat this action again.
My second account.
@James_Gurr That is unfortunate about the maximum post limit. I am guessing it was put in place because unruly students in the past have spammed. * Sigh.*
ok/ So looking at the code the following areas help store the information for knowing how many coins you have collected:
totalGold = 0
totalGold += coin.value
if totalGold >= 25:
examine what you have written so far and add these lines back in so that it is detecting the collection and exiting the while loop at the proper time with break
Where do you mean In the back? Do you mean
# Collect 25 gold, and then tell Naria the total.
`totalGold = 0
while True:
coins = hero.findItems()
totalGold += coins.value
for item in coins:
pos = item.pos
x = pos.x
y = pos.y
hero.moveXY(x, y)
if totalGold >= 25:
# >= means totalGold is greater than or equal to 25.
# This breaks out of the loop to run code at the bottom.
break
hero.moveXY(58, 33)
hero.say(totalGold)`
@Gurrman think about where you are adding to totalGold
and ask yourself if the coins
array has a value or if it is the individual coin that has a value.
Then ask yourself where should you be adding the value.