Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --getting cli args
- local args = {...}
- --defining variables
- local errors = 0
- local width = 0
- local range = 0
- local treesCut = 0
- --assigning values
- if args[1] ~= nil and args[1] > 0 then
- width = args[1] * 1
- else
- print("Please provide orchard width")
- errors = errors + 1
- end
- if args[2] ~= nil and args[2] > 0 then
- range = args[2] * 1
- else
- print("Please provide orchard range")
- errors = errors + 1
- end
- if turtle.getFuelLevel() == 0 then
- print("No fuel left - please refill")
- errors = errors + 1
- end
- --defining functions
- function fellTree()
- print("Felling tree...")
- local upMoves = 0
- turtle.dig()
- turtle.forward()
- while turtle.detectUp() do
- turtle.digUp()
- turtle.up()
- upMoves = upMoves + 1
- end
- --returning to ground
- for i = 1, upMoves, 1 do
- turtle.down()
- end
- print("Finished felling tree")
- end
- function strafeCol(column)
- if (column % 2) == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- elseif (column % 2) == 0 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- function clearColumn(length)
- for i = 1, length, 1 do
- if turtle.detect() then
- print("Detected tree")
- fellTree()
- treesCut = treesCut + 1
- else
- if i < length then
- turtle.forward()
- end
- end
- end
- end
- --main section begin
- if errors == 0 then
- for x = 1, width, 1 do
- clearColumn(range)
- if x < width then
- strafeCol(x)
- end
- end
- print("Returning to origin...")
- --return begin
- if (width % 2) == 1 then
- turtle.turnLeft()
- for i = 1, (width - 1), 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- for i = 1, (range - 1), 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- elseif (width % 2) == 0 then
- turtle.turnRight()
- for i = 1, (width - 1), 1 do
- turtle.forward()
- end
- turtle.turnRight()
- end
- print("Done")
- print("Chopped down " ..tostring(treesCut) .." trees")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement