Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Build Square V0.1 by QQII
- --Declerations
- local Arguments = { ... } --Program arguments
- local size = tonumber(Arguments[1]) or 0
- --Functions
- local function forward() --Moves forward
- if turtle.getFuelLevel() == 0 then
- shell.run("refuel", "all")
- if turtle.getFuelLevel() == 0 then
- print("ERROR: out of fuel")
- read()
- end
- end
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- end
- local function inventory_sort() --Fills the first slot with items from the other slots
- for i = 2, 16 do
- turtle.select(i)
- turtle.transferTo(1, turtle.getItemCount(i))
- if turtle.getItemSpace(1) == 0 then
- break
- end
- 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 square")
- if size <= 0 then
- io.write("Size: ")
- while size <= 0 do
- size = tonumber(read())
- end
- end
- --Main Script
- for i = 1, size do
- line(size)
- if i % 2 ~= 0 then
- turtle.turnRight()
- forward()
- turtle.turnRight()
- elseif i % 2 == 0 then
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement