Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- distance = 25 --turtle will go twice this far
- torchCounter = 3
- turtleName = os.getComputerLabel()
- ownerTabletId = 2 --what is the computer # of the owner's PDA where messages will be sent.
- --open wireless if available. modem is on the left arm.
- if peripheral.isPresent("left") == true then
- local wireless = peripheral.wrap("left")
- --wireless.open(4)
- rednet.open("left")
- wireless.open(65535)
- else
- print("no modem available")
- end
- --turtle movement functions
- function moveForward()
- while turtle.detect() == true do
- turtle.dig()
- os.sleep(0.5)
- --print("there is something in the way")
- --return to top of loop here.
- restartLoop = 1
- --else
- --turtle.forward()
- --restartLoop = 0 --this is junk but might do the job until i make a better way
- end
- --print("the function is actually running")
- turtle.forward()
- while turtle.detectUp() do
- turtle.digUp()
- os.sleep(0.5)
- end
- turtle.digDown()
- end
- --turtle inventory dump module
- --all slots will be dumped to the inventory in front of the turtle
- -- i = 1
- -- while i < 17 do
- -- slot = 1
- -- turtle.select(slot)
- -- turtle.drop()
- -- i = (i + 1)
- -- end
- --pick up all items from normal size chest
- --turtle will not be able to hold it all in one trip
- --i = 1
- -- while i < 27 do
- -- turtle.suck()
- -- os.sleep(0.25)
- -- i = (i + 1)
- -- end
- function moveUp()
- while turtle.detectUp() == true do
- turtle.digUp()
- os.sleep(0.5)
- --return to top and check again
- --else
- --turtle.up()
- end
- end
- function moveDown()
- while turtle.detectDown() == true do
- turtle.digDown()
- os.sleep(0.5)
- --return to top
- --else
- --turtle.down()
- end
- end
- function moveLeft() --not sure I like how this function works. the facing needs of a particular program may change
- turtle.turnLeft()
- moveForward()
- end
- --turn right then forward one. then dig up and down. then turn right again and dig up and down. then return to start. to turn twice then forward then left then forward then right.
- function rightSide()
- turtle.turnRight()
- moveForward() --displaced one space right
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- moveForward() --now -1x, -1y
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- turtle.turnRight()
- moveForward() --now -1x, 0y
- turtle.turnLeft()
- moveForward()
- turtle.turnRight()--now facing the same was as when we started
- end
- function leftSide()
- turtle.turnLeft()
- moveForward() --displaced one space left
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- moveForward() --now +1x, +1y
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- turtle.turnLeft()
- moveForward() --now +1x, 0y
- turtle.turnRight()
- moveForward()
- turtle.turnLeft()--now facing the same was as when we started
- end
- --refuel module
- --checks the turtle inventory for compatible fuel and uses it
- function refuel()
- limit = turtle.getFuelLimit()
- level = turtle.getFuelLevel()
- room = (limit) - (level)
- i = 1
- while i < 17 do
- slot = i
- turtle.select(slot)
- if room > 5000 then
- --i feel like something belongs here
- turtle.refuel()
- --i = (i + 1)
- print(turtle.getFuelLevel)
- --if i = 16 then
- end
- if i == 16 then
- print(turtle.getFuelLevel())
- end
- i = (i + 1)
- end
- end
- function checkFuel()
- checkLevel = turtle.getFuelLevel()
- if checkLevel < 500 then
- refuel()
- end
- if checkLevel < 250 then
- rednet.send(ownerTabletId, turtleName.." is running low on fuel.") --ad message protocol?
- --location data when available.
- end
- --if no fuel found return to start? or notify PDA
- end
- function detectReturnBlockage()
- if turtle.detect() then
- waiting(timerId) = os.startTimer(20)
- os.sleep(2)
- end
- while turtle.detect() do
- os.sleep(1)
- end
- if os.pullEvent("waiting(timerId") then
- rednet.send(2, turtleName.."here. Something is blocking my return!") --add coordinates
- end
- end
- function returnToSender()
- d=0
- turtle.turnRight()
- turtle.turnRight()--now facing 180
- while d < distance do
- turtle.forward() --use the simple forward to save time and not break any work happening behind the turtle
- detectReturnBlockage()
- turtle.forward() --it moves 2 spaces ahead so it needs to move 2 spaces back per distance counter
- detectReturnBlockage()
- d = d + 1
- end
- end
- --torch placement function
- --designate slot for torches
- --divide i or d by 7 or 8 and place each time it divides evenly or reset the counter when it hits 7
- function torch()
- if torchCounter == 6 then
- turtle.select(1)
- turtle.placeDown()
- torchCounter = 1
- else
- torchCounter = torchCounter + 1
- end
- end
- function dig()
- refuel()
- i=1
- while i < distance do
- moveForward()
- moveForward()
- rightSide()
- leftSide()
- i = i+1
- torch()
- print(torchCounter)
- checkFuel()
- end
- end
- function workComplete()
- rednet.send(ownerTabletId, turtleName.." has completed its task. Ready for work!")
- end
- --lets do this
- dig()
- returnToSender()
- workComplete()
- --send my pda a message when work is done
- --send one if contact is lost?
- -- i want something to say go X distance and check for full inventory, if full go back to the chest adn dump the inv,
- --then return to previous until total requested distance is completed and go back to start]]--
- --this particular program should dig a 3x3 hole to whatever distance I desire and put the contents in a chest.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement