Advertisement
thatparadox

tunnelCenter

Apr 28th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. startup = true
  2.  
  3. function saveDirection()
  4.   file = fs.open("direction","w")
  5.   file.write(direction)
  6.   file:close()
  7. end
  8.  
  9. if fs.exists("direction") == true then
  10.   file = fs.open("direction","r")
  11.   direction = file.readAll()
  12.   file:close()
  13. else
  14.   file = fs.open("direction","w")
  15.   file.write(0)
  16.   file:close()
  17.   direction = 0
  18. end
  19.  
  20. while tonumber(direction) ~= 0 do
  21.   if tonumber(direction) > 0 then
  22.     turtle.turnLeft()
  23.     direction = direction - 1
  24.   elseif tonumber(direction) < 0 then
  25.     turtle.turnRight()
  26.     direction = direction + 1
  27.   end
  28.   file = fs.open("direction","w")
  29.   file.write(direction)
  30.   file:close()
  31. end
  32.  
  33. while true do
  34.   if startup == false then
  35.     partners = false
  36.     topPartner = false
  37.     bottomPartner = false
  38.     while partners == false do
  39.       a,b = turtle.inspectUp()
  40.       if b == "No block to inspect" then
  41.         b = {"no","block"}
  42.       end
  43.       c,d = turtle.inspectDown()
  44.       if d == "No block to inspect" then
  45.         d = {"no","block"}
  46.       end
  47.       for k,v in pairs(b) do
  48.         if v == "computercraft:CC-Turtle" then
  49.           topPartner = true
  50.         end
  51.       end
  52.       for k,v in pairs(d) do
  53.         if v == "computercraft:CC-Turtle" then
  54.           bottomPartner = true
  55.         end
  56.       end
  57.       if topPartner == true and bottomPartner == true then
  58.         partners = true
  59.       end
  60.       sleep(.05)
  61.     end
  62.     while partners == true do -- new 20170428 check for cableLayer to move on
  63.       a,b = turtle.inspectUp()
  64.       if b == "No block to inspect" then
  65.         b = {"no","block"}
  66.       end
  67.       for k,v in pairs(b) do
  68.         if v ~= "computercraft:CC-Turtle" then
  69.           partners = false
  70.         end
  71.       end
  72.     end
  73.     startup = false
  74.   elseif startup == true then
  75.    startup = false
  76.    sleep(1.5)
  77.   end
  78.   sleep(.5)
  79.   turtle.dig()
  80.   turtle.forward()
  81.   turtle.turnRight()
  82.   direction = direction +1
  83.   saveDirection()
  84.   while turtle.getItemCount( turtle.getSelectedSlot() ) == 0 do
  85.     if turtle.getSelectedSlot() == 9 then
  86.       turtle.select(1)
  87.     else
  88.       turtle.select(turtle.getSelectedSlot() +1)
  89.     end  
  90.   end
  91.   turtle.place()
  92.   turtle.turnLeft()
  93.   direction = direction -1
  94.   saveDirection()
  95.   turtle.turnLeft()
  96.   direction = direction -1
  97.   saveDirection()
  98.   while turtle.getItemCount( turtle.getSelectedSlot() ) == 0 do
  99.     if turtle.getSelectedSlot() == 9 then
  100.       turtle.select(1)
  101.     else
  102.       turtle.select(turtle.getSelectedSlot() +1)
  103.     end  
  104.   end
  105.   turtle.place()
  106.   turtle.turnRight()
  107.   direction = direction +1
  108.   saveDirection()
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement