Spent 10 minutes just cleaning that a little not a huge difference, but now for making the height a variable size, thatll be a little complicated because the way your code is setup
term.clear()
term.setCursorPos(1,1)
x=tonumber(read())
thats how you want to get the input for the variable x which will determine that layers
additionally since as you add layers your distance from the chest changes you want to have another variable thats increased by 1 each layer and will go down by that much based on what layer its on
for example
--x was set to 3 in this case(3 layers) --
local z= 2 -- distance from chest to first layer where the turtle is placing blocks
if ---------------------- code that youll use to distinguish levels--- then
z=z+3 -- or whatever the distance of your levels is
local slot = 1
local turnRight = true
function sort()
while true do
for i=1,16 do
if turtle.getItemCount(i) > 0 then
return turtle.select(i)
end
end
printError("Out of resources, press a key after a refill.")
os.pullEvent("key")
end
end
function line()
sort()
for i=1, 8 do
turtle.forward()
turtle.placeDown()
end
sort()
turtle.forward()
turtle.placeDown()
turtle.forward()
sort()
end
function right()
sort()
turtle.turnRight()
for i=1,3 do
turtle.down()
end
for i=1,3 do
turtle.placeDown()
turtle.up()
end
turtle.placeDown()
sort()
end
function forward(x)
for i = 1, x do
turtle.forward()
end
end
function place()
turtle.place()
turtle.up()
turtle.forward()
turtle.select(6)
turtle.place()
turtle.select(1)
turtle.back()
turtle.down()
end
function chest()
turtle.turnRight()
turtle.turnRight()
forward(6)
turtle.turnRight()
forward(4)
dump()
for i =1,6 do
turtle.suck()
end
for i=1, 4 do
turtle.back()
end
turtle.turnRight()
forward(6)
end
function ice()
for i=1,3 do
turtle.up()
end
for i=1, 7 do
forward(4)
turtle.turnLeft()
forward(3)
place()
turtle.turnLeft()
forward(8)
turtle.turnRight()
place()
turtle.turnLeft()
turtle.turnLeft()
forward(6)
place()
turtle.turnLeft()
forward(8)
turtle.turnRight()
place()
turtle.turnLeft()
turtle.turnLeft()
forward(3)
turtle.turnLeft()
forward(4)
turtle.turnRight()
turtle.turnRight()
for i=1, 4 do
turtle.up()
end
end
for i=1,4 do
turtle.down()
end
end
function sandblock()
for i=1, 3 do
turtle.place()
turtle.back()
turtle.back()
end
turtle.place()
end
function cactusblock()
for i=1, 3 do
turtle.placeDown()
turtle.back()
turtle.back()
end
turtle.placeDown()
turtle.back()
end
function sand()
turtle.select(2)
turtle.turnRight()
forward(3)
turtle.turnLeft()
forward(2)
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
end
function sandd()
turtle.select(3)
turtle.turnRight()
forward(3)
turtle.turnLeft()
forward(2)
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
end
function cactus()
turtle.select(4)
turtle.turnLeft()
turtle.up()
turtle.up()
forward(3)
turtle.turnLeft()
forward(3)
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
for i=1,6 do
turtle.down()
end
end
function ground()
forward(5)
turtle.turnRight()
forward(5)
turtle.turnLeft()
turtle.down()
turtle.digDown()
for i=1, 26 do
turtle.down()
turtle.digDown()
end
turtle.down()
end
function dump()
for i = 16,1,-1 do
turtle.select(i)
turtle.dropDown()
end
end
function cactuss()
turtle.select(5)
turtle.turnLeft()
turtle.up()
turtle.up()
forward(3)
turtle.turnLeft()
forward(3)
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
for i =1, 6 do
turtle.down()
end
end
function center()
for j = 1, 9, 1 do
for i = 1, 9, 1 do
if turtle.getItemCount(slot) == 0 then
slot = slot + 1
turtle.select(slot)
turtle.digDown()
turtle.placeDown()
else
turtle.digDown()
turtle.placeDown()
end
if i < 9 then
turtle.dig()
turtle.forward()
end
end
if j < 9 then
if turnRight == true then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turnRight = false
else
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turnRight = true
end
end
end
end
function blocks()
sort()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.up()
turtle.up()
turtle.up()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.down()
turtle.down()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
sort()
end
for i=1, 7 do
if turtle.getItemCount(slot) == 1 then
slot = slot + 1
turtle.select(slot)
turtle.digDown()
turtle.placeDown()
else
turtle.up()
turtle.placeDown()
turtle.up()
turtle.placeDown()
turtle.up()
turtle.placeDown()
turtle.up()
turtle.placeDown()
line()
right()
line()
right()
line()
right()
line()
turtle.back()
turtle.turnRight()
turtle.forward()
turtle.down()
center()
blocks()
end
end
ground()
chest()
ice()
for i=1,4 do
sand()
cactus()
end
for i=1, 3 do
sandd()
cactuss()
end
If i confused you let me know :P/> good luck and cool code