[Javascript] Double Gaps=thing.pos doesn't work even if they said it did

Post Deleted
Cause:

Not formatted properly

I forgot to format it,im giving the formatted text

// 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(thing.pos.x + 20,y);
}


// The function build a fence on the left of something.
function buildLeftOf(something) {
    // buildXY a "fence" 20 meters to something's left.
        var enemy = hero.findNearestEnemy();
    hero.buildXY(thing.pos.x - 20,y);
}

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

That is the part where it says,thing.pos cant be defined,please help

When you are using the buildXY method there are three parts needed.

  1. the buildType (dependent on your hammer or other items) in this case “fence”
  2. X coordinate - can be pos.x
  3. Y coordinate - and pos.y

Below is a snapshot of the method details that you can look at while coding as a reminder.
building%20method

Hi Decoder999, Welcome to the CodeCombat discourse!
As well as what brooksy said, you also haven’t defined thing, in your buildRightOf() function. What is thing? (hint: look int the brackets of the function and you’ll see what you should use, instead of thing)
Neither have you defined y. Use thing .pos.y.
Do all of this for the function build LeftOf() as well.
:lion: :lion: :lion:
P.S. instead of making a new reply to post your formatted code (well done by the way, most people don’t do it first time), you can edit your topic by pressing the pencil button below your post.

1 Like