Why ut isnt working?it keeps saying wrong value of coins


#1

Collect coins until the clock reaches 30 seconds.

totalGold = 0
while True:
gold = hero.findNearestItem()
if gold:
hero.moveXY(gold.pos.x, gold.pos.y)
totalGold += gold.value
if hero.now() < 30:
break

Tell Naria how much gold you collected.

hero.moveXY(58, 33)
hero.say(totalGold)


#2

This line seems odd:

if hero.now() < 30:

It looks like you should break out of the coin collection loop when the clock is >= 30 seconds.


#3

but it says to collec5t coins until 30 sec


#4

and ive tried to write as you wrote >=30 it is not working neither


#5

it just keeps saying wrong value of collected coins


#6

Are you playing “Hoarding Gold” or is it a different level?


#7

This level is BOOKEEPER


#8

what is really interseting when 5 min ago when i run it it was working it even showed “success” and now i cant figure out whats wrong


#9

Oh I see.

It sometimes happens that your hero walks into more than one coin while moving to collect a coin. Try resubmitting (click “Submit”) again to see if it helps.

Also, I’ve just took a look at the sample code for the level, it should be if hero.now() > 30: then break out of the loop (that is, stop collecting).


#11

no it is not working:sob: i wrote as you said and tried resubmit
if hero.now() > 30:
break
:sob::sob::sob:


#12

Well, your code seems correct.

In any case, although in this level you are supposed to count the collected gold manually, you should be able to use hero.gold as well if your pendant is good enough.

Try with hero.say(hero.gold) to check.


#13

i ve already put sample code so it worked and yes you are right in sampke code they used hero.gold.But isnt it the same as my code? I mean they have to work in same way


#14

astill dont understand why it is rejecting my code


#15

hero.gold is the actual amount of gold your hero has at the moment, so it is 100% bulletproof for this level.

On the other hand, manually counting the gold you’ve collected can result in issues when you are walking towards a coin and your hero unexpectedly collects another coin that just spawned in the way, or when two coins spawn too close to each other and your hero collects both counting as just one. This is why I suggested resubmitting, every time you press “Submit” (not “run”) you get a new random seed and your game plays differently.

Did you manage to beat the level? If not, please post your updated code so I could try it here as well.


#16

Yes I beat this level FINALLY :sweat_smile: althougn with sample code .But thank you anyway your advices were really helpfull