# Help on fragile maze in Kithgard Dungeons{SOLVED}

**URL:** <https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341>\
**Category:** Level Help\
**Created:** [May 3, 2019, 6:52pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341 "2019-05-03T18:52:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johnny\_Fuentes-McClu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/johnny_fuentes-mcclu/32/9830_2.png) [@Johnny\_Fuentes-McClu](https://discourse.codecombat.com/u/Johnny_Fuentes-McClu)\
**Post date:** [May 3, 2019, 6:52pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341/1 "2019-05-03T18:52:27Z")

</div>

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.

```python
// 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.

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [May 3, 2019, 7:55pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341/2 "2019-05-03T19:55:11Z")

</div>

Two things:

1. You are missing the () on your up function, and don’t forget to call the function.

```python
function up{

```

1. Since you have already added dist to hero.pos.y for n, your “y” just needs to be n.

```python
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

```

---

<div class="post-metadata">

**Author:** ![Johnny\_Fuentes-McClu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/johnny_fuentes-mcclu/32/9830_2.png) [@Johnny\_Fuentes-McClu](https://discourse.codecombat.com/u/Johnny_Fuentes-McClu)\
**Post date:** [May 6, 2019, 2:40pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341/3 "2019-05-06T14:40:00Z")

</div>

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:

```python
// 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();
}

```

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [May 6, 2019, 3:04pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341/4 "2019-05-06T15:04:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Johnny\_Fuentes-McClu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/johnny_fuentes-mcclu/32/9830_2.png) [@Johnny\_Fuentes-McClu](https://discourse.codecombat.com/u/Johnny_Fuentes-McClu)\
**Post date:** [May 6, 2019, 6:28pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341/5 "2019-05-06T18:28:53Z")

</div>

so now he just goes around in a circle

---

<div class="post-metadata">

**Author:** ![Johnny\_Fuentes-McClu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/johnny_fuentes-mcclu/32/9830_2.png) [@Johnny\_Fuentes-McClu](https://discourse.codecombat.com/u/Johnny_Fuentes-McClu)\
**Post date:** [May 6, 2019, 6:49pm UTC](https://discourse.codecombat.com/t/help-on-fragile-maze-in-kithgard-dungeons-solved/18341/6 "2019-05-06T18:49:36Z")

</div>

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.
