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
[FIXED] My background of my nuclear control program is not updating
Started by GamerNebulae, Jun 15 2013 07:53 AM
2 replies to this topic
#1
Posted 15 June 2013 - 07: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:
#2
Posted 15 June 2013 - 09:03 AM
if heat < 4000 then -- This covers all values for "heat" that're less then 4000.
mon.setBackgroundColor(2048)
mon.setTextColor(1)
elseif heat > 3999 then -- This covers all values for "heat" that're more then 3999.
mon.setBackgroundColor(32)
mon.setTextColor(32768)
elseif heat > 4999 then -- This won't ever be evaluated. If "heat" is more then 4999, then
. -- it's also more then 3999, so the previous condition was already true.
.
.
Inverting the order of your conditions so that the HIGHEST values are checked first should sort it.
You also don't need the "for" loop in the start function. Since you already know the key names, you can simply refer to them directly - eg, "data.heat", "data.timeLeft", etc.
#3
Posted 15 June 2013 - 07:29 PM
You really should have edited your post in the New Members topic to let us know that you had successfully posted your own new topic.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











