# Help Sarven Gaps

**URL:** <https://discourse.codecombat.com/t/help-sarven-gaps/10088>\
**Category:** Uncategorized\
**Created:** [December 27, 2016, 1:48am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088 "2016-12-27T01:48:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenziYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renziyt/32/5374_2.png) [@RenziYT](https://discourse.codecombat.com/u/RenziYT)\
**Post date:** [December 27, 2016, 1:48am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/1 "2016-12-27T01:48:54Z")

</div>

Why does he keep on building the fence?  
 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/c/c976f1f11ed691eb0da99578c711b2cddb2bdb0c.png)

---

<div class="post-metadata">

**Author:** ![RenziYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renziyt/32/5374_2.png) [@RenziYT](https://discourse.codecombat.com/u/RenziYT)\
**Post date:** [December 27, 2016, 1:55am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/2 "2016-12-27T01:55:29Z")

</div>

Nevermind I got this level too.

---

<div class="post-metadata">

**Author:** ![RenziYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renziyt/32/5374_2.png) [@RenziYT](https://discourse.codecombat.com/u/RenziYT)\
**Post date:** [December 27, 2016, 1:56am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/3 "2016-12-27T01:56:36Z")

</div>

But I would still like help.

---

<div class="post-metadata">

**Author:** ![RenziYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renziyt/32/5374_2.png) [@RenziYT](https://discourse.codecombat.com/u/RenziYT)\
**Post date:** [December 27, 2016, 1:56am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/4 "2016-12-27T01:56:53Z")

</div>

Cause He aint doing it right, but it’s success

---

<div class="post-metadata">

**Author:** ![Ty\_Ler](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ty_ler/32/5322_2.png) [@Ty\_Ler](https://discourse.codecombat.com/u/Ty_Ler)\
**Post date:** [December 27, 2016, 2:17am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/5 "2016-12-27T02:17:36Z")

</div>

Its because once the enemy shows up their will always be an enemy. You need to make the fence then move down right after. Other wise your guy will never move down because its in the else. Which will never happen as long as their is an enemy in range.

---

<div class="post-metadata">

**Author:** ![RenziYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/renziyt/32/5374_2.png) [@RenziYT](https://discourse.codecombat.com/u/RenziYT)\
**Post date:** [December 27, 2016, 2:18am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/6 "2016-12-27T02:18:42Z")

</div>

Tyler go in that slack chat

---

<div class="post-metadata">

**Author:** ![The\_Lugiafan123](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@The\_Lugiafan123](https://discourse.codecombat.com/u/The_Lugiafan123)\
**Post date:** [December 28, 2016, 4:35pm UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/7 "2016-12-28T16:35:49Z")

</div>

Same problem here.  
Do you know how to make him do it correctly then?  
Because that would really help me.

---

<div class="post-metadata">

**Author:** ![taylerzy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/taylerzy/32/5214_2.png) [@taylerzy](https://discourse.codecombat.com/u/taylerzy)\
**Post date:** [December 28, 2016, 4:50pm UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/8 "2016-12-28T16:50:34Z")

</div>

There are a few ways you could handle it, but here’s one:  
Outside of your `while(true)` loop, keep track of your hero’s original X position:

```python
var originalX = hero.pos.x;

```

Then, every time you build a fence, you want to move down by 10, no matter what, so underneath the build, you use:  
`hero.moveXY(originalX, hero.pos.y);`  
to move back to the hero’s original x position (so he doesn’t get stuck), and:  
`hero.moveXY(originalX, hero.pos.y - 10);`  
to move him down 10 units.

---

<div class="post-metadata">

**Author:** ![Ty\_Ler](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ty_ler/32/5322_2.png) [@Ty\_Ler](https://discourse.codecombat.com/u/Ty_Ler)\
**Post date:** [December 28, 2016, 6:42pm UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/9 "2016-12-28T18:42:44Z")

</div>

Theirs only 2 steps build a fence and move down in the Y coordinates. Your the one that kind of needs to figure out on how to accomplish both of thoes steps. Giving out the code on how to move down pretty much solves half the problem.

What you can do is either move down or build a fence but if a fence is built make sure to also move down after so you dont get stuck in the row.

---

<div class="post-metadata">

**Author:** ![mzz](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@mzz](https://discourse.codecombat.com/u/mzz)\
**Post date:** [February 25, 2018, 5:57am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/10 "2018-02-25T05:57:43Z")

</div>

I’m bringing this thread back up because this makes no sense. I’ve tried it twenty different ways and tried the previous commenters solutions. Still no solve. Little buddy is forever making fences along a cliff wall.

```python
while(true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        // buildXY a "fence" 20 meters to enemy's left.
        hero.buildXY("fence", enemy.pos.x - 20, enemy.pos.y);
     } else {
        // moveXY down 10 meters.
        hero.moveXY(hero.pos.x, hero.pos.y - 10);
    }
}

```

---

<div class="post-metadata">

**Author:** ![mzz](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@mzz](https://discourse.codecombat.com/u/mzz)\
**Post date:** [February 25, 2018, 6:12am UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/11 "2018-02-25T06:12:36Z")

</div>

So I sat around thinking about this:

Obviously, the issue is the x -20 because by the time I’ve build the fence, they’ve moved and now my hero is trying to build a fence at x-20

Okay, so I tried to immediately build a second fence at x -2. That caused a giant mess.

I tried to the move after the 2nd fence. Still trash.

I’ve tried a var originalX like one of the replies: nope

I’ve tried adding distanceTo into the equation to see if I could game the system that way. It sort of worked but I kept running into distance loop issues.

Thanks whoever solves this one

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [February 25, 2018, 3:46pm UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/12 "2018-02-25T15:46:58Z")

</div>

What glasses are you using? Please post a screen shot of the equipment you are using for this level.

I believe the problem is the glasses you’re using. Try your code as above with regular wooden glasses. The infinity glasses can see through walls. Even after the fence is built, your hero can still see the ogres, so he keeps building fences.

---

<div class="post-metadata">

**Author:** ![mzz](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@mzz](https://discourse.codecombat.com/u/mzz)\
**Post date:** [February 25, 2018, 4:13pm UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/13 "2018-02-25T16:13:40Z")

</div>

Oh.

Lol.

When min/maxing goes wrong … 😂

---

<div class="post-metadata">

**Author:** ![bennypr0fane](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bennypr0fane/32/8337_2.png) [@bennypr0fane](https://discourse.codecombat.com/u/bennypr0fane)\
**Post date:** [May 24, 2018, 4:17pm UTC](https://discourse.codecombat.com/t/help-sarven-gaps/10088/14 "2018-05-24T16:17:50Z")

</div>

> [@MunkeyShynes](#):
>
> What glasses are you using? Please post a screen shot of the equipment you are using for this level.
> 
> I believe the problem is the glasses you’re using. Try your code as above with regular wooden glasses. The infinity glasses can see through walls. Even after the fence is built, your hero can still see the ogres, so he keeps building fences.

That solved it for me, I was using Twilight Glasses. Maybe we could put this in the hint section (This level won’t work wearing the Twilight Glasses!")?
