ThunderHooves help Lua coding

On ThunderHooves I tried inputing a code but then the character doesn’t move or anything. Can you send me code,

This is my code

-- Get to the oasis,
-- fencing off paths with randomized yaks on them as you go.
    local yak = self:findNearestEnemy()
    if yak then
        -- A yak is above you if yak.pos.y is greater than your pos.y.
        -- If the yak is above you, build a fence 10m below it.
        if yak.pos.y > self.pos.y then
            self:buildXY("fence", yak.pos.x, yak,pos.y-10)
        -- If the yak is below you, build a fence 10m above it.
            if yak.pos.y < self.pos.y then
            self:buildXY("fence", yak.pos.x, yak.pos.y+10)
        -- Move right 10m towards the oasis.
        self.moveXY(self.pos.x + 10, self.pos.y)

Hi! I get the feeling you didn’t read the FAQ. You need to format your code according to it, as indentation is extremely important in coding. Plus, it just makes it easier to read period. Also, we just don’t hand out code here, as the goal of the game is to learn HOW to code, which we can’t be done by copy/pasting.

What I want is to study off of the code and learn something new.

Hello, SpaceGaming, and welcome. We appreciate the attempt to format properly, but you didn’t quite manage it. I’ve done the formatting for you this time, but in the future you can put three backticks (`) surrounding your code on new lines.

Even if your intentions are good, there really is no substitute for making the code yourself. As such, it isn’t in your best interest to give you code.

You put your ends all at the very end of the code. This is not right. You need to put them at the end of each thing that requires an end, e.g an if-statement or a loop. Like this:

local enemy = self:findNearestEnemy()
local item = self:findNearestItem()
if enemy then
    --Do stuff
elseif item then
    --Do other stuff

Also on line 9, you have a comma instead of a period in yak,pos.y-10. Fix that.

Thank you, I finished the level