Posted 04 June 2012 - 09:57 PM
Hey there, I have a small problem with a program I'm creating to control a nuclear reactor. The reactor is controlled by the program and runs continuously for three hours before an automatic shutdown takes place, however, I do not want users to be able to terminate the program (I will install it as the startup program).
The problem is that when I have both the countdown AND blocking (ctrl+t) code in the same function the countdown does not take place.
Countdown progresses when holding down any key, it should countdown regardless of keys being pressed and should only terminate when ctrl+t is detected, which is what happens.
Help of any kind is greatly appreciated!
The problem is that when I have both the countdown AND blocking (ctrl+t) code in the same function the countdown does not take place.
function countdown()
term.clear()
term.setCursorPos(1,1)
s = 5
m = 0
h = 0
tleft = "yes"
delay = s + m*60 + h*3600
if tleft == "yes" then
while delay ~= 0 do
h = math.floor(delay/3600)
m = math.floor(delay/60 - h*60)
s = math.floor(delay -h*3600 -m*60)
print(" +----------------------------+")
print(" | Reactor Control |")
print(" +----------------------------+")
print(" Ctrl+T Emergency shutdown ")
print(" Reactor is " .. reactor .. "")
print(" Time until shutdown " .. h, ":", m, ":", s .. " ")
print(" +----------------------------+")
local event, param = os.pullEventRaw()
if event == "terminate" then
forceshutdown(main)
end
sleep(1)
delay = delay - 1
term.clear()
term.setCursorPos( 1, 1 )
if delay == 0 then
forceshutdown()
break
end
end
end
end
Countdown progresses when holding down any key, it should countdown regardless of keys being pressed and should only terminate when ctrl+t is detected, which is what happens.
Help of any kind is greatly appreciated!