Advertisement
Guest User

startup

a guest
Aug 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. -- initialize --
  2. reactors = {}
  3. status = {[0]=0,[1]=0,[2]=0,[3]=0, [4]=0}
  4.  
  5. -- functions --
  6. function getStatusData()
  7.   status = {[0]=0,[1]=0,[2]=0,[3]=0,[4]=0}
  8.   for num,reactor in pairs(reactors) do
  9.     stat = reactor.getReactorInfo().status
  10.     if stat == "offline" then
  11.       status[0] = status[0] + 1
  12.     elseif stat == "online" then
  13.       status[1] = status[1] + 1
  14.     elseif stat == "charging" then
  15.       status[2] = status[2] + 1
  16.     elseif stat == "charged" then
  17.       status[3] = status[3] + 1
  18.     elseif stat == "stopping" then
  19.       status[4] = status[4] + 1
  20.     end
  21.   end
  22. end
  23.  
  24. function getStatus()
  25.   if status[0] == 20 then
  26.     return "offline"
  27.   elseif status[1] == 20 then
  28.     return "active"
  29.   elseif status[2] == 20 then
  30.     return "charging"
  31.   elseif status[3] == 20 then
  32.     return "charged"
  33.   elseif status[4] == 20 then
  34.     return "stopping"
  35.   else
  36.     return "not balanced"
  37.   end
  38. end
  39.  
  40. function setup()
  41.   modem = peripheral.wrap("back")
  42.   names = modem.getNamesRemote()
  43.   for num,name in pairs(names) do
  44.     reactors[num] = peripheral.wrap(name)
  45.   end
  46. end
  47.  
  48. function setStatus(stat)
  49.   if stat == "stop" or status == "shutdown" then
  50.     for num,reactor in pairs(reactors) do
  51.       reactor.stopReactor()
  52.     end
  53.   elseif stat == "charge" then
  54.     for num,reactor in pairs(reactors) do
  55.       reactor.chargeReactor()
  56.     end
  57.   elseif stat == "start" then
  58.     for num,reactor in pairs(reactors) do
  59.       reactor.activateReactor()
  60.     end
  61.   end
  62. end
  63.  
  64. function interface()
  65.   term.clear()
  66.   term.setCursorPos(1,1)
  67.   getStatusData()
  68.   term.write("Status: "..getStatus())
  69.   term.setCursorPos(1,2)
  70.   term.write("Command: ")
  71.   command = read()
  72.   setStatus(command)
  73. end
  74.  
  75. -- start functions --
  76. setup()
  77. while true do interface() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement