Post Deleted
Cause:
Not formatted properly
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.
Below is a snapshot of the method details that you can look at while coding as a reminder.
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.
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.