i haven’t been able to pass this level for about a week and i am in need of some help
while (hero.time < 20) or (hero.gold:60):
#Collect coins
hero.say("I should pick up a coin")
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if hero.time>20 and hero.gold:60:
break
while hero.time>22:
hero.moveXY(16, 37)
hero.buildXY("fence", 21, 37)
Your code is slightly more complicated than it needs to be.
For the first while loop, what you want to check is if hero.gold < 60. That’s all. You don’t need to check time, and : doesn’t work, you need to use < (less than).
You also don’t need this:
Because while loops automatically break when their condition is satisfied (e.g. when you have more than 60 gold).
You also don’t need this:
Because moveXY and buildXY don’t need to be looped. They will work fine without a loop.
You also don’t need this:
I realise it may be for debugging purposes, but once you’ve made the above changes that I’ve mentioned, you won’t need it.
Danny
This first while-loop. should be while hero.gold < 60:
And then in this, delete these two:
In this while-loop, the start should be while hero.time > 16
Then move behind the fence (exact coordinates are 15,37)
And then outside of all while-loops, and under all. Build a fence at 21,37
Lydia
P.S. Comments really help!
Delete your hero.say() statement. Delete your if statement with the break. Then, delete you second while loop. You don’t need it. Just move behind the fence wall, and build a fence to protect yourself.