Posted 18 November 2013 - 11:56 AM
I have been working on a missile computer system with ICBM and the built in CC API for it. When you launch a missile, it does a 10 second countdown. During this countdown, I want to check for key presses of any kind and run another piece of code which asks you to enter a password to confirm the cancelling of the launch. The part I need help with, is how do I check for a key press but not wait for one? All my code so far looks like this:
Spoiler
local i = 0
local j = 10
local password = "hg548"
launcher = peripheral.wrap("left")
function checkForKeyPress()
while true do
local event, cancel = os.pullEvent("key")
if event == "key" then
write("Enter password to continue: ")
input = read("*")
if input == password then
print("Launch aborted. The computer will now restart.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
os.reboot()
end
end
end
end
write("Confirm launch: (y/n): ")
ans = read()
if ans == "y" then
write("Enter password to continue: ")
input = read("*")
if input == password then
print("Launch confirmed.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
for i=1, 100 do
print("Security checking..." .. i .. "%")
sleep(0.05)
term.clear()
term.setCursorPos(1,1)
end
while j~=0 do
print("Launching in " .. j .. " seconds")
sleep(1)
term.clear()
term.setCursorPos(1,1)
--parallel.run(checkForKeyPress)
j = j-1
end
launcher.launch()
os.reboot()
else
print("Password incorrect. The computer will now restart")
sleep(1)
term.clear()
term.setCursorPos(1,1)
os.reboot()
end
end
if ans == "n" then
print("Launch cancelled. The computer will now restart")
sleep(1)
term.clear()
term.setCursorPos(1,1)
os.reboot()
end