Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Program for digging and filling in tunnels
- blocks = {1,1,1,2}
- doBoth = false
- digging = false
- finished = false
- index = 1
- function refuel ()
- -- Refuel from the last slot if we are low
- if turtle.getFuelLevel() < 10 then
- i = turtle.getSelectedSlot()
- turtle.select(16)
- turtle.refuel()
- turtle.select(i)
- end
- end
- -- Setup main variables based on user input
- function setup ()
- print("Are we digging [dig], filling [fill], or both [both]?")
- op = read()
- responses = {["dig"] = true, ["fill"] = true, ["both"] = true}
- if (responses[op] ~= true) then
- print("Invalid response.")
- return false
- elseif (op == "dig") then
- digging = true
- elseif (op == "fill") then
- digging = false
- setupOffset()
- elseif (op == "both") then
- digging = true
- doBoth = true
- setupOffset()
- end
- return true
- end
- -- Setup for the offset variable
- function setupOffset ()
- print("Enter offset in blocks list: ")
- op = read()
- current = tonumber(op)
- end
- function main ()
- refuel()
- if digging then
- -- If we have reached an air block, finish digging phase
- if (turtle.inspect() == false) then
- digging = false
- if not doBoth then
- finished = true
- end
- return
- end
- turtle.dig()
- turtle.forward()
- else -- If Filling
- if (turtle.back()) then
- turtle.select(blocks[current])
- turtle.place()
- current = (current % table.getn(blocks)) + 1
- else -- Can't move back, finish fill phase
- finished = true
- end
- end
- end
- if (setup()) then
- while (not finished) do
- main ()
- end
- print("Finished Operation")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement