# Level coding help

I keep needing help with levels, can people help or give me the code for the levels I need help with? I am currently stuck on Sarven Road

I figured it out, but Im stuck on Thunderhooves

Yeah, Thunderhooves took me awhile to figure out. be sure to read the help/guide by clicking the blue help button under â€śrunâ€ť. That should tell you what to do, just not how to do it.

My main problem was that I didnâ€™t know how to get the yakâ€™s position. I believe this is the first level you need to find the position of something other than yourself. The syntax isnâ€™t really explained.

Eventually, I figured out that â€śyak.pos.yâ€ť gets you the yaks y position to compare to your y position â€śthis.pos.yâ€ť.
Use â€śbuildXYâ€ť to build a fence 10 meters above or below the yaks y position. Itâ€™s the same way you used â€śmoveXYâ€ť to move in the previous levels.

Hope this helps.

2 Likes

how do you code it to know the yak is 10m above or below you?

Simly i didnâ€™t do that, but if you want do , use distanceTo()

Here a JS sample without checking the distance:

``````loop {
var yak = this.findNearestEnemy();
if (yak) {
if (yak.pos.y < this.pos.y)
{
this.buildXY("fence", this.pos.x, yak.pos.y+10);
}
else if (yak.pos.y > this.pos.y)
{
this.buildXY("fence", this.pos.x, yak.pos.y-10);
}
} else {
// run 10m forward
this.moveXY(this.pos.x+10, 31);
}
}
``````

its not letting me do else

I was trying to avoid just pasting the answer, but I guess the catâ€™s already out of the bag.

``````loop {
var yak = this.findNearestEnemy();
if (yak) {
// A yak is above you if it's y is greater than your y.
// If the yak is above you, build a fence 10m below it.
if (yak.pos.y > this.pos.y) {
x = yak.pos.x;
y = yak.pos.y - 10;
this.buildXY("fence", x, y);
}
// If the yak is below you, build a fence 10m above it.
if (yak.pos.y < this.pos.y) {
x = yak.pos.x;
y = yak.pos.y + 10;
this.buildXY("fence", x, y);
}
} else {
// Move right 10m towards the oasis.
x = this.pos.x + 10;
y = this.pos.y;
this.moveXY(x, y);
}
}
``````

As you can see I didnâ€™t use distanceTo ()
You donâ€™t need to know how far the yak is above or below you, You only need to know if the yak is above or below you.

Just do what the sample code asks, nothing more.
If the yak is above you, build a fence 10 meters below it. The level was set up so that when you see the yak and build 10 meters below it, the fence gets built right above you and you can just keep moving right from there.