Posted 15 June 2013 - 08:53 AM
I recently made with a friend a program to control my nuclear reactor. One problem though, the screen isn't updating to the heat levels. This is the code:
function HowlerPulse()
rs.setOutput("top", true)
sleep(0.1)
rs.setOutput("top", false)
end
function Start()
a,b,c,data = NIR.get(1)
for i,j in pairs(data) do
if i == "heat" then
heat = tonumber(j)
elseif i == "reactorPoweredB" then
activity = tostring(j)
elseif i == "timeLeft" then
progress = tonumber(j)
elseif i == "output" then
output = tonumber(j)
end
end
end
function Calculate()
--progress percentage
pPercent = math.floor((progress/maxProgress)*100)
--heat percentage
hPercent = math.floor((heat/maxHeat)*100)
if heat < 4000 then
mon.setBackgroundColor(2048)
mon.setTextColor(1)
elseif heat > 3999 then
mon.setBackgroundColor(32)
mon.setTextColor(32768)
elseif heat > 4999 then
HowlerPulse()
mon.setBackgroundColor(16)
mon.setTextColor(32768)
elseif heat > 6999 then
mon.setBackGround(2)
mon.setTextColor(32768)
elseif heat > 8499 then
mon.setBackGround(16384)
mon.setTextColor(36788)
end
end
function Display()
mon.clear()
mon.setCursorPos(1,1)
mon.write(reactorName)
mon.setCursorPos(1,2)
mon.write("Activity: "..activity)
mon.setCursorPos(1,3)
mon.write("Output: "..output.." EU/t")
mon.setCursorPos(1,4)
mon.write("Progress: "..pPercent.."% "..progress)
mon.setCursorPos(1,5)
mon.write("Heat: "..hPercent.."% "..heat)
end
reactorName = "REACTOR 1"
mon = peripheral.wrap("back")
NIR = peripheral.wrap("left")
chatBox = peripheral.wrap("right")
maxProgress = 10000
maxHeat = 8500
activity = false
progress = 0
while true do
Start()
Calculate()
Display()
if progress < 1 then
activity = false
chatBox.say("Reactor is out of uranium!", 180, false)
end
sleep(1)
end