Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = { ... }
- if not args[0] and not args[1] then
- write("Usage: RoadWarrior <width> <distance>\n")
- exit()
- end
- width = tonumber(args[1])
- distance = tonumber(args[2])
- currentSelection = 1
- turningRight = true
- currentX = 1
- currentY = 1
- function determineMaxSelection ()
- for i=1,16 do
- if turtle.getItemCount(i) == nil or turtle.getItemCount(i) == 0 then
- return i - 1
- end
- end
- return 16
- end
- maxSelection = determineMaxSelection()
- if maxSelection < 1 then
- write("\nMust place the road blocks you wish to lay in the turtle, starting in the upper left corner.\n\n")
- exit()
- end
- function moveForward()
- if turtle.detect() then
- turtle.dig()
- end
- return turtle.forward()
- end
- function layBlock (selection)
- if selection > maxSelection then
- write("Ran out of blocks to lay. Stopping.\n\n")
- return false
- end
- leftToDrop = turtle.getItemCount(selection)
- if leftToDrop > 0 then
- if currentSelection ~= selection then
- turtle.select(selection)
- end
- turtle.digDown()
- turtle.placeDown()
- return selection
- else
- layBlock(selection + 1)
- return selection + 1
- end
- end
- function advance ()
- if currentX == 1 then
- turtle.turnRight()
- moveForward()
- currentX = currentX + 1
- elseif currentX == width then
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,(width - 1) do
- moveForward()
- end
- turtle.turnRight()
- moveForward()
- currentX = 1
- currentY = currentY + 1
- else
- moveForward()
- currentX = currentX + 1
- end
- end
- for currentY=1,distance do
- write("\nLaying row "..currentY.." of "..distance..".\n")
- for currentX=1,width do
- write(" laying position ("..currentX..", "..currentY..").\n")
- currentSelection = layBlock(currentSelection)
- if currentSelection == false then
- exit()
- end
- if turtle.detect() then
- turtle.dig()
- end
- advance()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement