Level coding help


#1

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


#2

I figured it out, but Im stuck on Thunderhooves


#3

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.


#4

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


#5

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

#6

its not letting me do else


#7

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.