Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- get arguments into the array
- local tArgs = { ... }
- if #tArgs < 1 or #tArgs > 2 then
- term.clear()
- term.setCursorPos(1,1)
- print ( "Incorrect arguments!" )
- print ( "--------------------")
- print ( "Syntax: bridge <length> <width>" )
- print ( "Both values are mandatory." )
- print ( "" )
- print ( "Type \"bridge ?\" or \"bridge help\" for more information." )
- return
- elseif (#tArgs < 2) and (tArgs[1] == '?' or tArgs[1] == 'help' or tArgs[1] == 'halp') then
- term.clear()
- term.setCursorPos(1,1)
- print ( "Syntax: bridge <length> <width>" );
- print ( "" )
- print ( "Example:" )
- print ( "--------" )
- print ( "\"bridge 20 15\"" )
- print ( "" )
- print ( "Creates a 20 long, 15 wide platform." )
- print ( "Both values are mandatory." )
- return
- end
- -- define length and width based on arguments
- local length = tonumber( tArgs[1] )
- local width = tonumber( tArgs[2] )
- -- helper variables
- local slot = 1
- local row = 1
- -- functions
- --------------
- local function placeBlock()
- while not turtle.placeDown() do
- -- if turtle can't place block check if it can dig down
- if not turtle.digDown() then
- -- if turtle can't dig down check other slots for building materials
- slot = slot + 1
- -- if it reaches slot 16 and not building materials are found
- -- stop and wait for player to refill it
- if slot > 16 then
- slot = 1
- term.clear()
- term.setCursorPos(1,1)
- print ("WARNING: No Blocks in my inventory.")
- print ("Please provide more materials to build.")
- print("")
- print (" - Press <Enter> to continue operation")
- print (" - Hold Ctrl + T to cancel operation.")
- input = read("*")
- end
- turtle.select(slot)
- end
- end
- end
- local function moveForward()
- while not turtle.forward() do
- -- if turtle can't move forward, check fuel levels
- fuel = turtle.getFuelLevel()
- -- if no fuel
- if fuel < 1 then
- -- stop and wait for fuel
- while not turtle.refuel() do
- term.clear()
- term.setCursorPos(1,1)
- print("WARNING: Fuel level is ".. fuel)
- print("Waiting for fuel...")
- end
- end
- end
- end
- local function makeTurn()
- turtle.forward()
- if row % 2 == 0 then
- -- if even number turn left
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- -- if not even, turn left
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- turtle.forward()
- row = row + 1
- end
- -- the job
- ------------
- turtle.select(slot)
- turtle.forward()
- for j = 1, width do
- for i= 1, length do
- placeBlock()
- if i~= length then
- moveForward()
- end
- end
- if j ~= width then
- makeTurn()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment