Posted 11 March 2014 - 02:59 AM
Hey guys,
Firstly: I'm playing on FTB Monster and focusing on BigReactors and Thermal Expansion for the following code.
I've been using a rather primitive and useless reactor control system that I built for a single reactor and energy cell that would start up the reactor when the EC got below 30% full and would then cut off once the reactor got to 90% full. I then added in another energy cell and ignored it in my program and then finally, I added a second reactor. When I did that, I modified the program a small amount to allow control of the secondary reactor. The program still only monitors one, though.
Here's the code for the program I've got:
Now, I'm trying to create a program that will allow me to add reactors in as and when I want to, along with improved energy cell handling and also display to an external monitor.
For the final product on the monitor, I want something that will display something like this (though preferably a little tidier than this version):
I've modified some code that someone helped me with for another program to iterate through attached peripherals and so I've got this:
My aim is to have something that will then run a "while true do" loop iterating through all attached peripherals and running all relevant functions on all of the energy cells and reactors and then displaying it to all attached monitors (for easy monitoring of reactors all around my base). Each reactor should be able to switch on and off independently, however, they should really only turn on when the attached energy cells get below a certain threshold.
My main question is, basically, how would I program the loop to iterate through each "peripheral" and control it and how do I access each peripheral from the tables I've created?
Thanks for any help!
Firstly: I'm playing on FTB Monster and focusing on BigReactors and Thermal Expansion for the following code.
I've been using a rather primitive and useless reactor control system that I built for a single reactor and energy cell that would start up the reactor when the EC got below 30% full and would then cut off once the reactor got to 90% full. I then added in another energy cell and ignored it in my program and then finally, I added a second reactor. When I did that, I modified the program a small amount to allow control of the secondary reactor. The program still only monitors one, though.
Here's the code for the program I've got:
Spoiler
hec = peripheral.wrap("cofh_thermalexpansion_energycell_1")
br1 = peripheral.wrap("BigReactors-Reactor_0")
br2 = peripheral.wrap("BigReactors-Reactor_1")
local maxStore = 0
local curStore = 0
local thirty = 0
local ninety = 0
local rTemp = 0
local rCurStore = 0
local rFuelAmount = 0
local rFuelMax = 0
local rWasteAmount = 0
local rEProduced = 0
local rCRodL = 0
maxStore = hec.getMaxEnergyStored("")
thirty = (maxStore/100)*30
while true do
curStore = hec.getEnergyStored("")
rTemp = br1.getTemperature()
rCurStore = br1.getEnergyStored()
rFuelAmount = br1.getFuelAmount()
rFuelMax = br1.getFuelAmountMax()
rWasteAmount = br1.getWasteAmount()
rEProduced = math.floor(br1.getEnergyProducedLastTick() + br2.getEnergyProducedLastTick())
term.clear()
term.setCursorPos(1,1)
print(" Energy Cell: "..curStore.." / "..maxStore.." RF")
print("")
print(" Temperature: "..rTemp.." C")
print(" Energy (Reactor): "..rCurStore.." RF")
print(" Fuel: "..rFuelAmount.." / "..rFuelMax.." mB")
print(" Waste: "..rWasteAmount.." mB")
print(" Energy Last Tick: "..rEProduced.." RF")
print("")
if curStore <= thirty then
br1.setActive(true)
br2.setActive(true)
elseif rCurStore >= 8000000 then
br1.setActive(false)
br2.setActive(false)
end
if br1.getActive then
print(" Reactor is: ON")
else
print(" Reactor is: OFF")
end
sleep(0.5)
end
Now, I'm trying to create a program that will allow me to add reactors in as and when I want to, along with improved energy cell handling and also display to an external monitor.
For the final product on the monitor, I want something that will display something like this (though preferably a little tidier than this version):
Reactors: 1 2 3
Temperature: X X X
Energy Stored: X X X
Fuel Amount: X X X
Waste Amount: X X X
Energy Last Tick: X X X
Status: ON ON OFF
Energy Cells: 1 2
Stored: X X
Max Storage X X
I've modified some code that someone helped me with for another program to iterate through attached peripherals and so I've got this:
Spoiler
local m = {}
local br = {}
local ec = {}
term.clear()
term.setCursorPos(1,1)
for a,b in pairs(peripheral.getNames()) do
if peripheral.getType(B)/>/> == "cofh_thermalexpansion_energycell" then
ec[#ec+1] = peripheral.wrap(B)/>/>
end
if peripheral.getType(B)/>/> == "BigReactors-Reactor" then
br[#br+1] = peripheral.wrap(B)/>/>
end
if peripheral.getType(B)/>/> == "monitor" then
m[#m+1] = peripheral.wrap(B)/>/>
end
end
My aim is to have something that will then run a "while true do" loop iterating through all attached peripherals and running all relevant functions on all of the energy cells and reactors and then displaying it to all attached monitors (for easy monitoring of reactors all around my base). Each reactor should be able to switch on and off independently, however, they should really only turn on when the attached energy cells get below a certain threshold.
My main question is, basically, how would I program the loop to iterate through each "peripheral" and control it and how do I access each peripheral from the tables I've created?
Thanks for any help!