View difference between Paste ID: 04MnLDbV and RQ9y2Z8R
SHOW: | | - or go back to the newest paste.
1
2
reactor = {}
3
capacitorBank = {}
4
5
local function init()
6
  --TODO: Search peripheral.getNames() to discover the names automatically.
7
  reactor = peripheral.wrap("BigReactors-Reactor_0")
8
  if reactor == nil then
9
    print("Can't find a reactor!")
10
    return false
11
  end
12
13
  -- could be handy later
14
  --reactor.setAllControlRodLevels(90)
15
16
  capacitorBank = peripheral.wrap("bottom")
17
  if capacitorBank == nil then
18
    print("Can't find a capacitor bank!")
19
    return false
20
  end
21
22
  return true
23
end
24
25
local function maybeTogglePower()
26
  local charge = capacitorBank.getEnergyStored() / capacitorBank.getMaxEnergyStored()
27
  if charge < 0.2 then
28
    reactor.setActive(true)
29
  elseif charge > 0.8 then
30
    reactor.setActive(false)
31
  end
32
end
33
34
35-
if !init() then return end
35+
if not init() then return end
36
 
37
while true do
38
  maybeTogglePower()
39
  os.sleep(3)
40
end