[Help] Double Gaps [RESOLVED]

Here is my Code:

For some reason, whenever my hero has built a fence, it moves back to rebuild the fence and causes a dead loop. I have tried for many hours but to no avail? Any advice on how to beat this level?

// Get the hero and the peasant to the south.

// The function move your hero down along the center line.
function moveDownCenter() {
var x = 40;
var y = hero.pos.y - 12;
hero.moveXY(x, y);
}

// The function build a fence on the right of something.
function buildRightOf(something) {
// buildXY a “fence” 20 meters to something’s right.
hero.buildXY(“fence”, something.pos.x + 20, something.pos.y);
}

// The function build a fence on the left of something.
function buildLeftOf(something) {
// buildXY a “fence” 20 meters to something’s left.
hero.buildXY(“fence”, something.pos.x - 20, something.pos.y);
}

while(true) {
var ogre = hero.findNearestEnemy();
var coin = hero.findNearestItem();
if (ogre) {
buildLeftOf(ogre);
}
if (coin) {
buildRightOf(coin);
}
moveDownCenter();
}


twilight glasses ?

1 Like

Yeah. Thanks that was the problem. It had infinite range :stuck_out_tongue:

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Number 1: Do not post solutions.
Number 2: When you post code, post using BEAUTIFUL formatting, according to FAQ.
Number 3: Do not revive dead threads. The last reply was 9 months ago. So don’t reply!
Number 4: Twilight Glasses was THE PROBLEM, not the solution.
Number 5: I’m pretty sure when Code Combat gave you the sample code, it did not give you the link. You probably plagarized this code from somewhere else.

Above are 5 reasons you should delete this post.