Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Build Rectangle V0.1 by QQII
- --Declerations
- local Arguments = { ... } --Program arguments
- local length = tonumber(Arguments[1]) or 0
- local width = tonumber(Arguments[2]) or length
- --Functions
- local function refuel()
- while turtle.getFuelLevel() <= 0 do
- shell.run("refuel", "all")
- if turtle.getFuelLevel() <= 0 then
- print("ERROR: out of fuel")
- read()
- end
- end
- turtle.select(1)
- end
- local function forward() --Moves forward
- refuel()
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- end
- end
- end
- local function inventory_sort() --Fills the first slot with items from the other slots
- for i = 2, 16 do
- if turtle.getItemSpace(1) == 0 then
- break
- end
- turtle.select(i)
- turtle.transferTo(1, turtle.getItemCount(i))
- end
- turtle.select(1)
- end
- local function place_down() --Places a block below the turtle
- while not turtle.detectDown() do
- while not turtle.placeDown() do
- inventory_sort()
- if turtle.getItemCount(1) == 0 then
- print("ERROR: out of items")
- read()
- end
- end
- end
- end
- local function line(l) --Places a line of size l
- for i = 2, l do
- place_down()
- forward()
- end
- place_down()
- end
- --User Inputs
- print("The turtle will build a rectangle")
- if length <= 0 then
- io.write("Length: ")
- while length <= 0 do
- length = tonumber(read())
- end
- else
- print("Length: " .. length)
- end
- if width <= 0 then
- io.write("Width: ")
- while width <= 0 do
- width = tonumber(read())
- end
- else
- print("Width: " .. width)
- end
- --Main Script
- refuel()
- for i = 2, width do
- line(length)
- if i % 2 ~= 0 then
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- elseif i % 2 == 0 then
- turtle.turnRight()
- forward()
- turtle.turnRight()
- end
- end
- line(length)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement