Need help on Backwoods Treasure not really sure whats wrong?


#1

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! : (


#2

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.


#3

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


#4

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!


#5

Or, you should use a distance variable, like:

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

Or you could use flags.


#6

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


#7

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.


#8

Never mind finally got it!!!


#9

This made me laugh. :slight_smile:


#10

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


#11

i think that could work thx! :slight_smile:


#12

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.