Advertisement
absorr

ccfactorycontrol

Sep 15th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local switchGrind = "1"
  2.  
  3. function readData()
  4.     h = fs.open("data", "r")
  5.     switchGrind = h.readLine() -- First Line: Grinder State (ON/OFF)
  6.     h.close()
  7. end
  8.  
  9. function saveData()
  10.     h = fs.open("data", "w")
  11.     h.writeLine(switchGrind)
  12.     h.close()
  13. end
  14.  
  15. function updateRs()
  16.     local c = 0
  17.     if switchGrind == "0" then
  18.         c = c + colors.white
  19.     end
  20.     rs.setBundledOutput("bottom", c)
  21. end
  22.  
  23. function display()
  24.     term.setBackgroundColor(colors.blue)
  25.     term.setTextColor(colors.white)
  26.     term.setCursorPos(1,1)
  27.     term.clearLine()
  28.     term.setCursorPos(11,1)
  29.     print "FACTORY CONTROL"
  30.    
  31.     term.setBackgroundColor(colors.black)
  32.     term.setCursorPos(1,3)
  33.     print "Grinder"
  34.    
  35.     term.setBackgroundColor(colors.white)
  36.     term.setCursorPos(12,3)
  37.     if switchGrind == "1" then
  38.         term.setTextColor(colors.green)
  39.         print "ON "
  40.     else
  41.         term.setTextColor(colors.red)
  42.         print "OFF"
  43.     end
  44. end
  45.  
  46. if fs.exists("data") then
  47.     readData()
  48. end
  49.  
  50. display()
  51.  
  52. while true do
  53.     local e, p1, p2, p3 = os.pullEvent()
  54.    
  55.     if e == "mouse_click" then -- on mouse click
  56.    
  57.         if p3 == 3 and p2 >= 11 then -- grinder toggled
  58.             if switchGrind == "1" then
  59.                 switchGrind = "0"
  60.             else
  61.                 switchGrind = "1"
  62.             end
  63.             updateRs()
  64.             saveData()
  65.             display()
  66.         end
  67.    
  68.     end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement