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)
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.
but it says to collec5t coins until 30 sec
and ive tried to write as you wrote >=30 it is not working neither
it just keeps saying wrong value of collected coins
Are you playing âHoarding Goldâ or is it a different level?
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
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).
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.
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
astill dont understand why it is rejecting my code
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.
Yes I beat this level FINALLY althougn with sample code .But thank you anyway your advices were really helpfull
1 Like