SHARE
TWEET

Sample of my code

a guest Apr 25th, 2017 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("buttonAPI")
  2.  
  3. page1=buttonAPI.new()
  4. page2=buttonAPI.new()
  5.  
  6. reactorTemp = 600
  7. rotorSpeed = 1800
  8.  
  9. info = {}
  10. t = {}
  11. m = {}
  12. r = {}
  13. c = {}
  14.  
  15. function getDevices()
  16.   for _, name in pairs(peripheral.getNames()) do
  17.     if peripheral.getType(name) == "BigReactors-Turbine" then
  18.       table.insert(t, peripheral.wrap(name))
  19.     elseif peripheral.getType(name) == "monitor" then
  20.       table.insert(m, peripheral.wrap(name))
  21.     elseif peripheral.getType(name) == "BigReactors-Reactor" then
  22.       table.insert(r, peripheral.wrap(name))
  23.     elseif peripheral.getType(name) == "draconic_rf_storage" then
  24.       table.insert(c, peripheral.wrap(name))
  25.     elseif peripheral.getType(name) == "Induction Matrix" then
  26.       IM = peripheral.wrap(name)
  27.       IMtf = true
  28.     end
  29.   end
  30.   print("Turbines found: "..#t)
  31.   print("monitors found: "..#m)
  32.   print("Reactors found: "..#r)
  33.   print("Energy Cores  : "..#c)
  34. end
  35.  
  36. function numberMonitors()
  37.   for i = 1, #m do
  38.     m[i].setBackgroundColor(colors.black)
  39.     m[i].clear()
  40.     m[i].setCursorPos(1,1)
  41.     m[i].setTextScale(5)
  42.     m[i].write(tostring(i))
  43.   end
  44. end
  45.  
  46. function addMon(name)
  47.   mon = string.gsub(name,"%a","")
  48.   mon = string.gsub(mon,"%s","")
  49.   mon = tonumber(mon)
  50.   m[mon].write(" OK")
  51.   table.insert(info, currentText..": "..mon)
  52.   if numOfMonitors == 2 then
  53.     currentPage = page2
  54.   else
  55.     numOfMonitors = numOfMonitors + 1
  56.   end
  57. end
  58.  
  59. function addPage1Buttons()
  60.   posX = 1
  61.   posY = 4
  62.   for i=1,#m do
  63.     page1:add("monitor "..i, nil, posX, posY, posX+11, posY+2, colors.blue, colors.lime)
  64.     posY=posY+4
  65.     if posY >= 17 then
  66.       posY=4
  67.       posX=posX+13
  68.     end
  69.   end
  70. end
  71.  
  72. function addPage2Buttons()
  73.   local reactor100 = {
  74.           " -100 ",
  75.           label = "r-100"
  76.   }
  77.  
  78.   local reactor10 = {
  79.           "  -10 ",
  80.           label = "r-10"
  81.   }
  82.  
  83.   local reactor5 = {
  84.           "  -5  ",
  85.           label = "r-5"
  86.   }
  87.  
  88.   local reactorr5 = {
  89.           "  +5  ",
  90.           label = "r+5"
  91.   }
  92.  
  93.   local reactorr10 = {
  94.           "  +10 ",
  95.           label = "r+10"
  96.   }
  97.  
  98.   local reactorr100 = {
  99.           " +100 ",
  100.           label = "r+100"
  101.   }
  102.  
  103.   page2:add(reactor100, function() reactorTemp = reactorTemp - 100 end, 1, 5, 6, 5, colors.purple, colors.lime)
  104.   page2:add(reactor10, function() reactorTemp = reactorTemp - 10 end, 8, 5, 13, 5, colors.purple, colors.lime)
  105.   page2:add(reactor5, function() reactorTemp = reactorTemp - 5 end, 15, 5, 20, 5, colors.purple, colors.lime)
  106.   page2:add(reactorr5, function() reactorTemp = reactorTemp + 5 end, 32, 5, 37, 5, colors.purple, colors.lime)
  107.   page2:add(reactorr10, function() reactorTemp = reactorTemp + 10 end, 39, 5, 44, 5, colors.purple, colors.lime)
  108.   page2:add(reactorr100, function() reactorTemp = reactorTemp + 100 end, 46, 5, 51, 5, colors.purple, colors.lime)
  109.  
  110.   local turbine100 = {
  111.           " -100 ",
  112.           label = "t-100"
  113.   }
  114.  
  115.   local turbine10 = {
  116.           "  -10 ",
  117.           label = "t-10"
  118.   }
  119.  
  120.   local turbine5 = {
  121.           "  -5  ",
  122.           label = "t-5"
  123.   }
  124.  
  125.   local turbinee5 = {
  126.           "  +5  ",
  127.           label = "t+5"
  128.   }
  129.  
  130.   local turbinee10 = {
  131.           "  +10 ",
  132.           label = "t+10"
  133.   }
  134.  
  135.   local turbinee100 = {
  136.           " +100 ",
  137.           label = "t+100"
  138.   }
  139.  
  140.   page2:add(turbine100, nil, 1, 12, 6, 12, colors.purple, colors.lime)
  141.   page2:add(turbine10, nil, 8, 12, 13, 12, colors.purple, colors.lime)
  142.   page2:add(turbine5, nil, 15, 12, 20, 12, colors.purple, colors.lime)
  143.   page2:add(turbinee5, nil, 32, 12, 37, 12, colors.purple, colors.lime)
  144.   page2:add(turbinee10, nil, 39, 12, 44, 12, colors.purple, colors.lime)
  145.   page2:add(turbinee100, nil, 46, 12, 51, 12, colors.purple, colors.lime)
  146.  
  147.   page2:add("save",function() end,46,19,51,19,colors.lime,colors.purple)
  148.   page2:add("exit",function() end,1,19,6,19,colors.purple,colors.lime)
  149. end
  150.  
  151. function numBoxes()
  152.   if currentPage == page2 then
  153.     term.setTextColor(colors.white)
  154.     term.setBackgroundColor(colors.gray)
  155.     pos = {}
  156.     pos[1] = 3
  157.     pos[2] = 10
  158.     for v=1,2 do
  159.       for i=1,3 do
  160.         term.setCursorPos(22,pos[v]+i)
  161.         term.write(string.rep(" ",9))
  162.       end
  163.     end
  164.     term.setCursorPos(25,5)
  165.     term.write(tostring(reactorTemp))
  166.     term.setCursorPos(25,12)
  167.     term.write(tostring(rotorSpeed))
  168.   end
  169. end
  170.  
  171. function title()
  172.   term.setTextColor(colors.orange)
  173.   term.setBackgroundColor(colors.black)
  174.   if currentPage == page1 then
  175.     if numOfMonitors == 0 then
  176.       currentText = "Reactors"
  177.     elseif numOfMonitors == 1 then
  178.       currentText = "Turbines"
  179.     elseif numOfMonitors == 2 then
  180.       currentText = "Energy Cores"
  181.     end
  182.     term.setCursorPos(12,2)
  183.     term.write("Select a monitor for: "..currentText)
  184.   else
  185.     term.setCursorPos(14,3)
  186.     term.write("Avg. Reactor Temperature")
  187.     term.setCursorPos(18,10)
  188.     term.write("Avg. Rotor Speed")
  189.   end
  190. end
  191.  
  192. function save()
  193.   local file = fs.open("config","w")
  194.   local text = ""
  195.   for _, line in pairs(info) do
  196.     text = text..line.."\n"
  197.   end
  198.   file.write(text)
  199.   file.close()
  200. end
  201.  
  202. numOfMonitors = 0
  203. currentPage=page1
  204. getDevices()
  205. numberMonitors()
  206. addPage1Buttons()
  207. addPage2Buttons()
  208.  
  209. while true do
  210.   currentPage:draw()
  211.   title()
  212.   numBoxes()
  213.   local event, p1 = currentPage:handleEvents(os.pullEvent())
  214.   if event == "button_click" then
  215.     if currentPage == page1 then
  216.       if not page1.buttonList[p1].active then
  217.         page1:toggleButton(p1)
  218.         addMon(p1)
  219.       end
  220.     else
  221.       if p1 == "exit" then
  222.         break
  223.       elseif p1 == "save" then
  224.         save()
  225.       else
  226.         page2:flash(p1)
  227.         page2:run(p1)
  228.       end
  229.     end
  230.   end
  231. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top