Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = turtle
- function moveForward()
- if t.detect() then
- t.dig()
- t.forward()
- else
- t.forward()
- end
- end
- function moveUpward()
- if t.detectUp() then
- t.digUp()
- t.up()
- else
- t.up()
- end
- end
- function moveDownward()
- if t.detectDown() then
- t.digDown()
- t.down()
- else
- t.down()
- end
- end
- function fuelTurtle(distance)
- t.refuel((distance/80)+1)
- end
- function moveDistanceForward(distance)
- while distance > 0 do
- moveForward()
- distance = distance - 1
- end
- end
- function moveDistanceUpward(distance)
- while distance > 0 do
- moveUpward()
- distance = distance - 1
- end
- end
- function moveDistanceDownward(distance)
- while distance > 0 do
- moveDownward()
- distance = distance - 1
- end
- end
- function distanceInput()
- print("Input distance: ")
- num = io.read()
- num = tonumber(num)
- return num
- end
- function turnAround()
- t.turnLeft()
- t.turnLeft()
- end
- function moveUp()
- if t.detectUp() then
- t.digUp()
- t.up()
- else
- t.up()
- end
- end
- ---------------
- function shaft()
- distance = distanceInput()
- fuelTurtle(distance*2)
- moveDistanceForward(distance)
- moveUp()
- turnAround()
- moveDistanceForward(distance)
- end
- function hole()
- distance = distanceInput()
- print("Return? 0 = no, 1 = yes")
- yon = tonumber(io.read())
- fuelTurtle(distance)
- moveDistanceDownward(distance)
- fuelTurtle(distance)
- if not yon == 0 then
- moveDistanceUpward(distance)
- end
- end
- --------------
- function main()
- print("1 = Shaft, 2 = Hole")
- func = io.read()
- func = tonumber(func)
- if func == 1 then
- shaft()
- elif func == 2 then
- hole()
- else
- print("Please input a valid function")
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement