Advertisement
thatparadox

Cable Layer

Apr 19th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 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("distance") then
  10.   file = fs.open("distance","r")
  11.   distance = file.readAll()
  12.   file:close()
  13. else
  14.   term.clear()
  15.   term.setCursorPos(1,1)
  16.   print("How far do I go?")
  17.   term.write(">")
  18.   distance = read()
  19.   term.clear()
  20.   term.setCursorPos(1,1)
  21.   print("Oh my god")
  22.   sleep(1)
  23.   file = fs.open("distance","w")
  24.   file.write(distance)
  25.   file:close()
  26. end
  27.  
  28. if fs.exists("slot") == true then
  29.   file = fs.open("slot","r")
  30.   slot = file.readAll()
  31.   file:close()
  32.   turtle.select(tonumber(slot))
  33. else
  34.   turtle.select(1)
  35. end
  36.  
  37. if fs.exists("direction") == true then
  38.   file = fs.open("direction","r")
  39.   direction = file.readAll()
  40.   file:close()
  41. else
  42.   file = fs.open("direction","w")
  43.   file.write(0)
  44.   file:close()
  45.   direction = 0
  46. end
  47.  
  48. while tonumber(direction) ~= 0 do
  49.   if tonumber(direction) > 0 then
  50.     turtle.turnLeft()
  51.     direction = direction - 1
  52.   elseif tonumber(direction) < 0 then
  53.     turtle.turnRight()
  54.     direction = direction + 1
  55.   end
  56.   file = fs.open("direction","w")
  57.   file.write(direction)
  58.   file:close()
  59. end
  60.  
  61. while tonumber(distance) > 0 do
  62.   if startup == false then
  63.     partner = false
  64.     while partner == false do
  65.       a,b = turtle.inspectDown()
  66.       if b == "No block to inspect" then
  67.         b = {"no","block"}
  68.       end
  69.       for k,v in pairs(b) do
  70.         if v == "computercraft:CC-Turtle" then
  71.           partner = true
  72.         end
  73.       sleep(.05)
  74.       end
  75.     end
  76.   else
  77.     sleep(3)
  78.     startup = false
  79.   end
  80.   turtle.dig()
  81.   sleep(.5)
  82.   if fs.exists("placed") == false then
  83.     turtle.forward()
  84.     distance = distance - 1
  85.     file = fs.open("placed","w")
  86.     file.write("filler")
  87.     file:close()
  88.   end
  89.   turtle.turnRight()
  90.   direction = direction +1
  91.   saveDirection()
  92.   turtle.turnRight()
  93.   direction = direction +1
  94.   saveDirection()
  95.   turtle.place()
  96.   if turtle.getItemCount( turtle.getSelectedSlot() ) == 0 then
  97.     turtle.select(turtle.getSelectedSlot() +1)
  98.     slot = turtle.getSelectedSlot() +1
  99.     file = fs.open("slot","w")
  100.     file.write(slot)
  101.     file:close()
  102.   end
  103.   fs.delete("placed")
  104.   turtle.turnLeft()
  105.   direction = direction -1
  106.   saveDirection()
  107.   turtle.turnLeft()
  108.   direction = direction -1
  109.   saveDirection()
  110.   term.clear()
  111.   term.setCursorPos(1,1)
  112.   print(distance)
  113. end
  114.  
  115. fs.delete("distance")
  116. fs.delete("slot")
  117. fs.delete("direction")
  118. term.clear()
  119. term.setCursorPos(1,1)
  120. print("Job done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement