guitarplayer616

[Debug] schem turtle

Nov 25th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. function saveToConsole(str)
  2.     local h = fs.open("console","a")
  3.     if type(str) ~= "table" then
  4.         str = tostring(str)
  5.         h.writeLine(str)
  6.         h.close()
  7.     else
  8.         for i,v in pairs(str) do
  9.             h.writeLine(i,": ",v)
  10.         end
  11.     end
  12. end
  13.  
  14.  
  15.  
  16. function saveVarsToConsole(name)
  17.     local h = fs.open(name,'w')
  18.     local env = getfenv()
  19.     for i,v in pairs(env) do
  20.         if i then
  21.             h.write(i)
  22.             if v then
  23.                 --h.write("("..tostring(type(v))..")")
  24.                 h.write(': ')
  25.                 h.writeLine(v)
  26.             end
  27.         end
  28.     end
  29.     h.close()
  30. end
  31.  
  32. function saveVarsToFile()
  33.     local h = fs.open("currentVars",'w')
  34.     local env = getfenv()
  35.     for i,v in pairs(env) do
  36.         if type(v) == "string" then
  37.             h.write(tostring(i))
  38.             h.write(" = ")
  39.             h.write([["]]..tostring(v)..[["]])
  40.         elseif type(v) == "table" then
  41.             h.write(i)
  42.             h.write(" = ")
  43.             h.write(textutils.serialize(v))
  44.         end
  45.     end
  46.     h.close()
  47. end
  48.  
  49. function loadVars()
  50.     local h = fs.open("currentVars",'r')
  51. end
  52.  
  53. function checkIfRefill()
  54.     local _,inFront = turtle.inspect()
  55.     local _,below = turtle.inspectDown()
  56.     local mem = turtle.getSelectedSlot()
  57.     turtle.select(16)
  58.     local check = turtle.getItemDetail()
  59.     if check and check.name ~= "EnderStorage:enderChest" then
  60.         if not turtle.dropDown() then
  61.             if not turtle.drop() then
  62.                 turtle.dropUp()
  63.             end
  64.         end  
  65.     end
  66.     if inFront or below then
  67.         if inFront.name == "EnderStorage:enderChest" then
  68.             turtle.select(enderchest1)
  69.             turtle.dig()
  70.         end
  71.         if below.name == "EnderStorage:enderChest" then
  72.             turtle.select(enderchest2)
  73.             turtle.digDown()
  74.         end
  75.     end
  76.     turtle.select(mem)
  77. end
Add Comment
Please, Sign In to add comment