!= in lua is ~= and yes you can do something like
while length ~= x do
stuff
end.
If I tell it to build a 5x5x2 room I get a 6x6x1. I notice that you have:
Y = Y + 1
X = X + 1
This is adding to this size. If I remove it I get 5x5x1. There is some logic issues in the code, need to better position him after the first layer so he can start on the second properly. As well as the logic to digUp doesn't seem to work. I'm going to play with it some more.
Okay I've got it so that it will do multiple layers. Part of your problem you were never resetting the checkLength and checkWidth vars after doing the first floor. As you will see there is some logical issues as to the turtle placement after the last row is dug. Probably needs to add in some extra intelligence to the turtle so it knows it is at the last row and position itself towhere it can cleanly start the next layer.
See comments in code for what was done:
Spoiler
checkLength = 1 -- changed to 1 to accommodate for turtle being in position 1, otherwise room would be selected length + 1.
checkWidth = 0
checkHeight = 0
down = Y
local rownum = X - 1 -- added so turtle will know to position itself for the next layer
--Y = Y + 1 -- removed adding extra layers
--X = X + 1 -- removed adding extra rows/columns
switch = false
while checkHeight < Y do
checkHeight = checkHeight + 1
while checkWidth < X do
while checkLength < X do
turtle.dig()
turtle.forward()
checkLength = checkLength + 1
end
checkLength = 1 -- updated so that you only get selected room size instead of +1
-- print ("Room Status HxWxL: ")..checkHeight..("x")..checkWidth..("x")..checkLength..(" ")--
if checkWidth == rownum then -- added for end of layer intel
for x=1, 2 do
turtle.turnLeft()
checkWidth = checkWidth + 1
end
elseif switch == false then
turtle.turnRight()
turtle.dig()
turtle.forward()
checkWidth = checkWidth + 1
turtle.turnRight()
turtle.dig()
switch = true
else
turtle.turnLeft()
turtle.dig()
turtle.forward()
checkWidth = checkWidth + 1
turtle.turnLeft()
turtle.dig()
switch = false
end
end
turtle.digUp() -- added so turtle would remove obstructions above prior to trying to move up
turtle.up()
checkLength = 0 -- reset for new layer
checkWidth = 0 -- reset for new layer
switch = false -- reset for new layer
end
while down > 0 do
turtle.down()
down = down - 1
end
Let me know if you run into anymore issues or need help with making the needed updates.Okay I was bored so I just fixed it all the way… The code should work as you intended now..
You will have issues if you run into sand or gravel. I would update your forward movements to be something like what I have in my
Turtle Tree Farmer API. Take a look at the forward() function.