Posted 27 October 2012 - 03:12 AM
I've got a lua script I'm working on which is meant to monitor and display information regarding a reactor, which I can do! I'm now trying to expand my knowledge and adapt the script to include maintance of said reactor… This is where I hit my problem, as soon as the uranium starts to take "damage" it stops registering as being present in the reactor core and my system requests more Uranium Cell's to burn, which in turn clogs the whole system up…
I've spent ages trying to establish why I've got a problem, I'm sure its to do with the final part of the :sub section but I'm tired and being blind and can't spot the solution, sorry. Any help would be great.
Code is below:
I've spent ages trying to establish why I've got a problem, I'm sure its to do with the final part of the :sub section but I'm tired and being blind and can't spot the solution, sorry. Any help would be great.
Code is below:
-- Output to monitor
local monside = "left";
if peripheral.isPresent(monside) then
if peripheral.getType(monside) == "monitor" then
monitor = peripheral.wrap(monside);
term.redirect(monitor);
end
end
--id tags--
name_ucell = 'item.itemCellUran';
name_uneardepleted = 'item.itemCellUranEmpty';
name_ureenriched = 'item.itemCellUranEnriched';
name_ice = 'tile.ice';
-- Content control
local max_ice = 192;
local max_ucell = 15;
local total_ice = 0;
local total_ucell = 0;
-- Master power button
local power = false;
function SortContents(side, sensor, target)
for i,v in pairs(sensors.getSensorReadingAsDict(side, sensor, target, 'ReactorContent')) do
-- Ice
if v:sub(-2-#name_ice, -3) == name_ice then
i_qty = tonumber(string.match(v, '^(%d*)%*'));
total_ice = total_ice + i_qty;
-- Depleated Uranium
elseif v:sub(-2-#name_uneardepleted, -3) == name_uneardepleted then
-- code to work out how much depleated there is
-- Enriched Uranium
elseif v:sub(-2-#name_ureenriched, -3) == name_ureenriched then
-- code to work out how much enriched uranium there is
-- Uranium
elseif v:sub(-2-#name_ucell, -3) == name_ucell then
u_qty = tonumber(string.match(v, '^(%d*)%*'));
total_ucell = total_ucell + u_qty;
end
end
-- Display information
print("Uranium in Reactor : "..total_ucell.."/ "..max_ucell);
print("Ice in Reactor : "..total_ice.."/"..max_ice);
end
-- Loop through the program updating the display
while true do
-- Get Sensor details
local sensor = "Reactor 1";
local side = sensors.getController();
local targets = sensors.getAvailableTargetsforProbe(side, sensor, "Reactor");
-- Use the two lines below to get all available readings on this Probe (debugging)
-- local s = sensors.getAvailableReadings(side, sensor);
-- print(textutils.serialize(s));
-- Get Probe details for Reactor status
local r = sensorsData.getProbe("ic2", "reactor");
local reactor = sensors.getSensorReadingAsDict(side, sensor, targets[1], "Reactor");
-- Get Probe details for Reactor Contents
local contents= sensors.getSensorReadingAsDict(side, sensor, targets[1], "ReactorContent");
-- Clear the screen
term.clear();
term.setCursorPos(1,4);
-- Get Reactor state and adjust as required
if colors.test(rs.getBundledInput("back"), colors.orange) then
print("Reactor Power: OFF");
print("! Thermal Cut Off !");
power = false;
elseif colors.test(rs.getBundledInput("back"), colors.white) then
print("Reactor Power: OFF");
print("! Capacitor Full !");
power = false;
rs.setBundledOutput("back", colors.yellow);
elseif total_ice < max_ice then
-- load the reactor with ice (send a pulse)
print("Reactor Power: ON");
print("Loading Ice");
else
power = true;
print("Reactor Power: ON");
end
-- Get Reactor information
m_cmb = reactor[r.size.val];
m_cur_heat = reactor[r.heat.val];
m_max_heat = reactor[r.size.val]*1000+10000;
m_out = reactor[r.energy.val];
-- Get Ractor Content Information (Make it readable!)
SortContents(side, sensor, targets[1]);
-- Check to see if we need to load Uranium
if total_ucell < max_ucell then
rs.setBundledOutput("back", colors.lightBlue);
end
-- Check to see if we need ice
if total_ice < max_ice then
print(total_ice.."<"..max_ice);
rs.setBundledOutput("back", colors.magenta);
end
-- Set local world and time format
local time = os.time();
time = textutils.formatTime(time, false);
term.setCursorPos(1,2);
-- Display world time
print ("World Time: "..time);
-- Move Cursor then display Reactor information
term.setCursorPos(1, 8);
-- Display information
print ("Reactor Size : "..m_cmb);
print ("Cur. Heat : "..m_cur_heat);
print ("Max. Heat : "..m_max_heat);
print ("Output (Eu/t) : "..m_out);
-- Reset totals before next loop
total_ice = 0;
total_ucell = 0;
-- set delay
sleep(0.5);
-- Kill all cable signals
rs.setBundledOutput("back", 0);
-- Check to see if the power kill is on, if it is ensure it gets put back in place
if power == true then
rs.setBundledOutput("back", colors.yellow);
end;
sleep (0.5);
end