Need help on Backwoods Treasure not really sure whats wrong?

Again not really sure whats wrong with the code my hero IS collecting coins
and killing enemies at the same time. But, then the moment the coins run out in that grove he stops attacking enemies or moving. Please help! I have strugled with this lvl for at least a month now! : (

You are trying to access a property of item before you check if it’s actually there. Move the coordinate definitions inside the if item: block.

You should incorporate the use of flags to move to the center so you can find the nearest coin from there.

Also you can use

if not item:

moveXY(x,y)

instead of using flag, to define position, where your hero can see coin. I prefer this way because I don’t like manual usage of flags and try to avoid that if it’s possible) Good luck!

Or, you should use a distance variable, like:

if item:
    distance = distanceTo(item)
if distance < 20:
moveXY(x, y)

Or you could use flags.

Uhh. Can u guys please type the real code that makes u win? I have been stuck on this for hours

No, we most definitely cannot type the real code that makes you win. That goes against our forum-policy and will prevent any of the future readers from learning a thing.

Never mind finally got it!!!

This made me laugh. :slight_smile:

using if flag does not help tryed did not work:( ! also using else does not work. my hero just gets stuck there where the coins end in that grove

i think that could work thx! :slight_smile:

This is because you haven’t checked if there is an item. If there is no item, it will attempt to define a pos that doesn’t exist. Instead you should check if item: first.