# Help on fragile maze in Kithgard Dungeons{SOLVED}

So I know that you can cheat this level but doing so does not help you learn how to use the `hero.isPathClear` function.
So when I run my code it gives me an error saying that my end position is wrong.

``````// Escape from the maze!
// Some doors are blocked, some open when you are near them.

var dist = 16;
var start = {x: 18, y: 19};
var x = hero.pos.x;
var y = hero.pos.y;
var n = y + dist;
var s = y - dist;
var e = x + dist;
var w = x -dist;
function up{
if (hero.isPathClear(hero.pos, {"x": hero.pos.x,"y": hero.pos.y + n})) {
hero.moveXY(hero.pos.x,hero.pos.y + n);
start = {"x": hero.pos.x,"y": hero.pos.y};
}
}

// Cheat Way:
//hero.moveXY(18, 51);
//hero.moveXY(51, 50);
//hero.moveXY(51, 81);
//hero.moveXY(66, 81);
//hero.moveXY(66, 50);
//hero.moveXY(82, 50);
//hero.moveXY(82, 98);
//hero.moveXY(114, 98);

``````

for now Iâ€™ve only put one of the direction becuase once I get that one I can do the rest.

Two things:

1. You are missing the () on your up function, and donâ€™t forget to call the function.
``````function up{
``````
1. Since you have already added dist to hero.pos.y for n, your â€śyâ€ť just needs to be n.
``````var y = hero.pos.y;
var n = y + dist;
{"x": hero.pos.x,"y": hero.pos.y + n} // your n variable already includes the hero.pos.y + 16
``````

so when I did this he only moved twice i feel like there should be a `while (true):` loop in the functions or a `break;` method but I am unsure as to where:

``````// Escape from the maze!
// Some doors are blocked, some open when you are near them.

var dist = 16;
var start = {x: 18, y: 19};
var x = hero.pos.x;
var y = hero.pos.y;
var n = y + dist;
var s = y - dist;
var e = x + dist;
var w = x -dist;
function up(){
if (hero.isPathClear(hero.pos, {"x": hero.pos.x,"y": n})) {
hero.moveXY(hero.pos.x,n);
}
}
function down(){
if (hero.isPathClear(hero.pos, {"x": hero.pos.x,"y": s})) {
hero.moveXY(hero.pos.x, s);
start = {"x": hero.pos.x,"y": hero.pos.y};
}

}

function right(){
if (hero.isPathClear(hero.pos, {"x":e,"y":hero.pos.y})) {
hero.moveXY(e ,hero.pos.y);
start = {"x": hero.pos.x,"y": hero.pos.y};
}
}
function left(){
if (hero.isPathClear(hero.pos, {"x": w,"y": hero.pos.y})) {
hero.moveXY(w,hero.pos.y);
start = {"x": hero.pos.x,"y": hero.pos.y};
}
}

// Cheat Way:
//hero.moveXY(18, 51);
//hero.moveXY(51, 50);
//hero.moveXY(51, 81);
//hero.moveXY(66, 81);
//hero.moveXY(66, 50);
//hero.moveXY(82, 50);
//hero.moveXY(82, 98);
//hero.moveXY(114, 98);
while(true) {
up();
up();
down();
right();
left();
}

``````

Since the variables you are using to give the check location (x,y,n,s,e,w) are outside of the while loop, they are only seeing the original values. Place them in the while loop and they should reassign the values based on your current location after your hero moves.

Something to think about. I donâ€™t see you using the â€śstartâ€ť variable for any of your other components. Do you really need that? You reassign the variable, but never use it to give new coordinates.

1 Like

so now he just goes around in a circle

Nvm I got some help and the only hint the gave me was to use `Vector....`'s and after they said that I got it.