Restless dead - 'I can't get there'

hi

I can’t move at all after collecting the coins from the yeti’s dead body, can anyone take a look at my codes? thanks

def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        
def collect():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
 
 
        
        
hero.moveXY(58, 15)


while True:
    attack()
    collect()
hero.moveXY(19, 40)

Hi, please format your code, I may be able to read it now, but the more complex your code gets the more important indentation (the gap between lines) is. So it would be nice if you could get into the habit of doing it now:

Danny

1 Like

the reality is, for the last couple of times when I copied pasted the codes in the forum while didn’t click that button, it got me the right indentations, but I have no idea why it didn’t work this time. maybe you should look into it

It is usually easier to just do as Danny says. He knows what he’s doing. Also, not doing so could encourage others to accidentally fail to format their code correctly and just gives us a lot more work. Can you do that for us @xiaoming? Thanks.

I’ve fixed everything once I got the comment, please don’t think that I’m challenging the helper. for sure I’ll put that button in all my codes from now on, but it was a just a little question about why it worked for the last couple of times

Don’t worry, I’m not claiming that you’re challenging. Sorry if it came off that way. There is always that risk, but don’t worry, I know you’ll be chill. I just spent a while correcting people on it. It just make it easier for the people like us to find the answers and spend less time having the “how to format your code correctly” thing on our clipboard. :laughing:

yeah, for sure, mate, haha, I’m very sure this is not going to be the last time you correct me, lol

Hi,
look at these lines:

How long does a while True loop run before you end it? (:infinity:-infinitely)
So… Will hero.moveXY(19, 40) ever run?
I hope this helps, and thank you for your lovely formatting!
Danny

hey mate, thanks for getting back to this one.

it’s not an infinite loop. cuz after the yeti got killed and I’ve collected all the coins, the loop supposed to be done and execute the moveXY()

but the hero just move to a corner and say “I can’t get there”

1 Like

Try using a two step approach…move out a bit, so the final destination is in line of sight:
image

good point, I’ll try, thanks