Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local target = -1
- if(arg[4] == nil) then
- print("not enough arg")
- return
- end
- local length = tonumber(arg[1])
- local weight = tonumber(arg[2])
- local pMode = nil
- local orient = "RIGHT"
- local turntFlag = false
- if(arg[4] == "l") then
- orient = "LEFT"
- turntFlag = true
- elseif (arg[4] == "r") then
- orient = "RIGHT"
- else
- print("not valid orient!")
- return
- end
- if(arg[3] == "ver") then
- pMode = "VER"
- turntFlag = false
- elseif (arg[3] == "hor") then
- pMode = "HOR"
- else
- print("not valid mode!")
- return
- end
- print("input confirm to start work");
- if(io.read() ~= "confirm" ) then
- print("u not confirm!")
- return
- end
- print("start work!")
- local emptyFlag =false
- local bkslot = 2
- local function turtleSelfCheck()
- -- check fuel
- if(turtle.getFuelLevel() < 100) then
- turtle.select(1)
- turtle.refuel(1)
- end
- -- check space
- turtle.select(bkslot)
- if(emptyFlag == false) then
- while (turtle.getItemCount() == 0) do
- bkslot = bkslot + 1
- if(turtle.getItemCount(2) ~= 0) then
- bkslot = 2
- break
- end
- if(bkslot > 16) then
- os.shutdown()
- end
- turtle.select(bkslot)
- end
- end
- end
- local function turtleMove(edgeFlag)
- if(pMode == "HOR") then
- if(edgeFlag) then
- if(turntFlag == false) then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- turntFlag = not turntFlag
- else
- turtle.forward()
- end
- elseif (pMode == "VER") then
- if(turntFlag == false) then
- if(edgeFlag) then
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turntFlag = not turntFlag
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turntFlag = not turntFlag
- end
- else
- turtle.up()
- end
- else
- if(edgeFlag) then
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turntFlag = not turntFlag
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turntFlag = not turntFlag
- end
- else
- turtle.down()
- end
- end
- end
- end
- local function turnCheck()
- if(orient == "RIGHT") then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- end
- local eFlag = false
- while (length>0) do
- local count = 0
- while true do
- -- self check
- turtleSelfCheck()
- -- place
- if(pMode == "HOR") then
- turtle.placeDown()
- elseif(pMode == "VER") then
- turtle.place()
- end
- turtle.forward()
- -- move
- if(turtle.detectDown()) then
- turnCheck()
- turntFlag = not turntFlag
- break
- else
- end
- count = count + 1
- --
- end
- while (count > target) do
- turtleSelfCheck()
- turtle.back()
- turtle.placeDown()
- count = count -1
- end
- turnCheck()
- turntFlag = not turntFlag
- length = length - 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement