Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Treasured in ice help

while True:
    downClear = hero.isPathClear(hero.pos,{'x':hero.pos.x,'y':hero.pos.y - 16})
    rightClear = hero.isPathClear(hero.pos,{'x':hero.pos.x- 16, 'y':hero.pos.y})
    leftClear = hero.isPathClear(hero.pos,{'x':hero.pos.x + 16, 'y':hero.pos.y})
    upClear= hero.isPathClear(hero.pos,{'x':hero.pos.x,'y':hero.pos.y + 16})
    if downClear:
    if rightClear:
    if leftClear:
    if upClear:
        hero.moveXY(x, y)
1 Like

Please explain more about your issue. A screenshot and a description of errors and what happens when you run your code would be most helpful!

P.S. Good Job with formatting your code!

Hi there! I haven’t used Python yet, but i (might) see the potential problem, in case the path to the right is clear twice in a row, or if 2 paths are clear at the same time. (like moving back and forth, or to the side and then up/down against a wall or similar)

in case this is the actual problem (I’m not at that level yet myself)
try checking only one “directionClear” at a time, instead of all four one after another within the same check.
You might also want to store your previous direction as a variable and avoid turning back, unless there’s no other path clear besides the one to turn back to.

hope my thoughts might be of use :slight_smile:


@Shurutsue that is exactly my problem.

Perhaps you could use elif instead of if.

1 Like

Actually, ifs are their own boolean system, so there’s not really that much difference

Though, if I’m not wrong, you check (start position) if there’s a clear path to the sides, then you check each individually, so you check if down is free, if it is, you move there, then check if from the starting position to the right was free, if it is, then it also moves right… and so on until it reaches the end of the check for up. so if all directions were free, it would move down, right, left, up (return to it’s starting position) before actually updating if from the new position after the movement there’s a free path. so I too would guess having the three other if’s be elif’s
That, or to use continue after the movement command, which would let the while loop repeat, without moving the other steps. (That is, if I am correct).

Also, if I’m not mistaken, your “check” if the right side is free, aswell as the movement to the right actually checks and moves to the left (not that it would necessarily cause an error in your case or similar, but might be worth noting that the coordinate x:0 should actually be at the very left and for example x:100 at the right side. (or is it different for python?)

1 Like

You’re missing a critical piece in your code. You have to check if you have already went to that coordinate or not. You’ll go to the same place over and over again if you don’t check if you went there or not.