[Solved] Fence Builder - Bottom left corner not being built

For some reason, the bottom left corner in Fence Builder is not being built. I can’t find any fault within my code since I copied and pasted from the example code and changed the values around, so it should’ve worked perfectly.

This is what is happening:

and this is my code:

// Build a fence around the farm.
// Take coordinates of the opposite corners.
var customer = hero.findNearest(hero.findFriends());
var x1 = customer.leftBottom.x;
var y1 = customer.leftBottom.y;
var x2 = customer.rightTop.x;
var y2 = customer.rightTop.y;
var step = 4;
// Let's build the bottom side.
for (var x = x1 + step; x <= x2; x += step) {
    hero.buildXY("fence", x, y1);
}
// Then the right side.
for (var y = y1 + step; y <= y2; y += step) {
    hero.buildXY("fence", x2, y);
}
// Build the top side.
for (var x = x1 + step; x <= x2; x += step) {
    hero.buildXY("fence", x, y2);
}
// // Build the left side.
for (var y = y1 + step; y <= y2; y += step) {
    hero.buildXY("fence", x1, y);
}

What’s the issue here?

1 Like

There are a couple of errors in your code. Remember that each variable, x1, y1, x2, and y2, all stand for a corner. So to help visualize, you could replace the variable with leftBottom and etc. Some of the arrows in the if else statements are pointed the wrong direction, some are >=. Also, you reference the wrong corners sometimes, for example, maybe y1 instead x1 (just an example, may not be true). It’s not always +=. Some if statements will require -=. The level seems intimidating at first, but if you realize that + means moving up or right and - means moving left or down, the level becomes a piece of :cake:. (It’s hard to help with this level without giving away too much.)

2 Likes

Thanks! I figured it out by changing a small detail.

2 Likes

sorry, i need help with my code:

# Build a fence around the farm.

# Take coordinates of the opposite corners.
customer = hero.findNearest(hero.findFriends())
x1 = customer.leftBottom.x
y1 = customer.leftBottom.y
x2 = customer.rightTop.x
y2 = customer.rightTop.y

step = 4

# Let's build the left side.
for y in range(y2 - step, y1 - 1, -step):
    hero.buildXY("fence", x1, y)
# Build the bottom side.
for x in range(x1 + step, x2 + 1, step):
    hero.buildXY("fence", x, y1)
# Then the right side.
for y in range(y1 + step, y2 + 1, step):
    hero.buildXY("fence", x2, y)
# Build the top side.
for x in range(x2 + step, x1 + 1, step):
    hero.buildXY("fence", x, y2)

my hero doesn’t build the top:
image
@_TD_RodYT

// Build a fence around the farm.
// Take coordinates of the opposite corners.
var customer = hero.findNearest(hero.findFriends());
var x1 = customer.leftBottom.x;
var y1 = customer.leftBottom.y;
var x2 = customer.rightTop.x;
var y2 = customer.rightTop.y;
var step = 4;
// Let’s build the bottom side.
for (var x = x1 + step; x <= x2; x += step) {
hero.buildXY(“fence”, x, y1);
}
// Then the right side.
for (var y = y1 + step; y <= y2; y += step) {
hero.buildXY(“fence”, x2, y);
}
// Build the top side.
for (var x = x1 + step; x <= x2; x += step) {
hero.buildXY(“fence”, x, y2);
}
// // Build the left side.
for (var y = y1 + step; y <= y2; y += step) {
hero.buildXY(“fence”, x1, y);
}

what is all the punctuation about?
i don't get it.

sorry if i seem rude.

here is my new code:

customer = hero.findNearest(hero.findFriends())
x1 = customer.leftBottom.x
y1 = customer.leftBottom.y
x2 = customer.rightTop.x
y2 = customer.rightTop.y
step = 4

# Let's build the left side.
for y in range(y2 - step, y1 - 1, -step):
    hero.buildXY("fence", x1, y)
# Build the bottom side.
for x in range(x1 + step, x2 + 1, step):
    hero.buildXY("fence", x, y1)
# Then the right side.
for y in range(y1 + step, y2 + 1, step):
    hero.buildXY("fence", x2, y)
# Build the top side.
for x in range(x2 - step, x1 - 1, step):
    hero.buildXY("fence", x, y2)


is there anything wrong?

You’re using python, whereas @/Hikrdox was using JavaScript :slight_smile:
JavaScript has more “punctuation” than python does :slight_smile:

ok, thank you for that info, but can you help me?

gtg bye! :slight_smile:

Btw Td rodyt is not active so please maybe try not to ping them.

then what should i do?