Posted 30 June 2012 - 11:09 PM
So, i have this code and some reason, it's not work.
When energy storage is full, it work fine, but when it's no longer full, it doesn't change the status.
I can't understand why this won't work…
When energy storage is full, it work fine, but when it's no longer full, it doesn't change the status.
I can't understand why this won't work…
local cableSide = "back"
local coolDownCol = colors.white
local heatUpCol = colors.red
local controlCol = colors.black
local energyCol = colors.blue
local lightsCol = colors.pink
local storageStateCol = colors.green
local cool1Col = colors.orange
local cool2Col = colors.cyan
local cool3Col = colors.yellow
local cool4Col = colors.purple
local fastCoolCol = colors.lime
local companyName = "Company"
os.pullEvent = os.pullEventRaw
local reactorEnabled = true
local reactorEmpty = false
local storageFull = false
local manualShutdown = false
local coolDown = false
local timerSinceStart = 0
local width, height = term.getSize()
local function clearScreen()
term.clear()
term.setCursorPos(1, 1)
term.write("Nuclear Reactor Control System")
term.setCursorPos(width-#companyName+1, height)
term.write(companyName)
end
local function step()
local hot = rs.testBundledInput(cableSide, heatUpCol)
local cold = rs.testBundledInput(cableSide, coolDownCol)
local full = rs.testBundledInput(cableSide, storageStateCol)
local lights = rs.testBundledInput(cableSide, lightsCol)
local control = rs.testBundledInput(cableSide, controlCol)
local energyFlow = rs.testBundledInput(cableSide, energyCol)
local cool1 = rs.testBundledInput(cableSide, cool1Col)
local cool2 = rs.testBundledInput(cableSide, cool2Col)
local cool3 = rs.testBundledInput(cableSide, cool3Col)
local cool4 = rs.testBundledInput(cableSide, cool4Col)
local fastCool = rs.testBundledInput(cableSide, fastCoolCol)
if not control then
if reactorEnabled then
timerSinceStart = timerSinceStart + 1
if hot then
reactorEnabled = false
coolDown = true
elseif timerSinceStart >= 20 and not energyFlow then
reactorEmpty = true
elseif full then
reactorEnabled = false
storageFull = true
end
if reactorEmpty and energyFlow and not full then
reactorEmpty = false
end
end
if not reactorEnabled then
timerSinceStart = 0
if not full and storageFull then
reactorEnabled = true
storageFull = false
elseif not cold and coolDown then
reactorEnabled = true
coolDown = false
end
end
else
timerSinceStart = 0
end
clearScreen()
term.setCursorPos(1, 3)
term.write("Current status: ")
if reactorEmpty then
term.write("Cells Depleted")
elseif storageFull then
term.write("Energy Storage Full")
rs.setBundledOutput(cableSide, controlCol)
elseif control and reactorEnabled then
term.write("Maintenance mode")
elseif reactorEnabled then
term.write("Active")
elseif not reactorEnabled and (hot or cool) then
term.write("Cooling")
else term.write("Unknow") end
term.setCursorPos(1, 4)
term.write("Temperature: ")
if hot then term.write("|Cold |Warm >Hot")
elseif cold then term.write("|Cold >Warm |Hot")
else term.write(">Cold |Warm |Hot") end
term.setCursorPos(1, 5)
term.write("Lights: ")
if lights then term.write(">On |Off")
else term.write("|On >Off") end
term.setCursorPos(1, 6)
term.write("Cooling: ")
if cool1 then term.write(">1 ") else term.write("|1 ") end
if cool2 then term.write(">2 ") else term.write("|2 ") end
if cool3 then term.write(">3 ") else term.write("|3 ") end
if cool4 then term.write(">4 ") else term.write("|4 ") end
term.setCursorPos(1, 7)
term.write("Cooling speed up: ")
if fastCool then term.write(">On |Off") else term.write("|On >Off") end
sleep(0.25)
end
while true do step() end