Posted 09 January 2015 - 09:49 PM
Hi
I recreated a program but you can still terminate it eventho i added this :
I recreated a program but you can still terminate it eventho i added this :
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
Now how can i improve this program and make it unterminatable.
local mon = peripheral.wrap("top")
local pass = "1234"
local passlen = string.len(pass)
local press = "";
tblpad = {};
for i=0,10 do
tblpad[i] = {}
for x=0,10 do
tblpad[i][x] = "x"
end
end
tblpad[2][2] = "1"
tblpad[4][2] = "2"
tblpad[6][2] = "3"
tblpad[2][3] = "4"
tblpad[4][3] = "5"
tblpad[6][3] = "6"
tblpad[2][4] = "7"
tblpad[4][4] = "8"
tblpad[6][4] = "9"
tblpad[4][5] = "0"
function drawpad()
mon.setBackgroundColor(colors.blue)
mon.setCursorPos(1,1)
mon.write(" Code? ")
mon.setCursorPos(1,2)
mon.write(" 1 2 3 ")
mon.setCursorPos(1,3)
mon.write(" 4 5 6 ")
mon.setCursorPos(1,4)
mon.write(" 7 8 9 ")
mon.setCursorPos(1,5)
mon.write(" 0 ")
end
function countdown(c)
for i=1,c do
mon.setCursorPos(1,1)
mon.write(" ")
mon.setCursorPos(1,2)
mon.write(" ")
mon.setCursorPos(1,3)
mon.write(" ".. c .." ")
mon.setCursorPos(1,4)
mon.write(" ")
mon.setCursorPos(1,5)
mon.write(" ")
sleep(1)
c = c-1
end
end
function codeaccept()
rs.setOutput('left', true)
mon.setBackgroundColor(colors.red)
mon.setCursorPos(1,1)
mon.write("-------")
mon.setCursorPos(1,2)
mon.write("Prepare")
mon.setCursorPos(1,3)
mon.write(" To ")
mon.setCursorPos(1,4)
mon.write("Launch ")
mon.setCursorPos(1,5)
mon.write("-------")
sleep(5)
end
function after()
rs.setOutput('back', true) -- Activates Launcher
mon.setBackgroundColor(colors.red)
mon.setCursorPos(1,1)
mon.write("-------")
mon.setCursorPos(1,2)
mon.write("Standby")
mon.setCursorPos(1,3)
mon.write(" For ")
mon.setCursorPos(1,4)
mon.write("Impact ")
mon.setCursorPos(1,5)
mon.write("-------")
sleep(2)
rs.setOutput('back', false)
rs.setOutput('left', false)
sleep(10)
end
function opendoor()
codeaccept()
countdown(10)
after()
os.reboot()
end
function wrongpass()
rs.setOutput('left', true) -- Activates the Siren
mon.setBackgroundColor(colors.red)
mon.setCursorPos(1,1)
mon.write(" ")
mon.setCursorPos(1,2)
mon.write(" CODE ")
mon.setCursorPos(1,3)
mon.write(" ")
mon.setCursorPos(1,4)
mon.write("DENIED! ")
mon.setCursorPos(1,5)
mon.write(" ")
sleep(20)
rs.setOutput('left', false)
drawpad()
end
drawpad()
while true do
event, side, xPos, yPos = os.pullEvent("monitor_touch")
if tblpad[xPos][yPos] ~= "x" then
mon.setCursorPos(xPos, yPos)
mon.setBackgroundColor(colors.red)
mon.write(tblpad[xPos][yPos])
sleep(0.2)
mon.setCursorPos(xPos, yPos)
mon.setBackgroundColor(colors.green)
mon.write(tblpad[xPos][yPos])
press = press .. tblpad[xPos][yPos]
if string.len(press) == passlen and press == pass then
press = ""
opendoor()
elseif string.len(press) == passlen and press ~= pass then
press = ""
wrongpass()
end
end
end
Edited on 10 January 2015 - 01:32 PM