Help Sarven Gaps


#1

Why does he keep on building the fence?


#2

Nevermind I got this level too.


#3

But I would still like help.


#4

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


#5

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.


#6

Tyler go in that slack chat


#7

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


#8

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:

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.


#9

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.


#10

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.

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);
    }
}

#11

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


#12

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.


#13

Oh.

Lol.

When min/maxing goes wrong … :joy:


#14

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!")?