Posted 05 August 2013 - 08:57 PM
Here's the gist…
I'm trying to make a security system with a forcefield. the outside uses a terminal that needs to be unlocked with a password, while on the inside, I use a touch screen I activate to send off a rednet message to the first machine.
I've tried using a method from this forum (http://www.computerc...ultiple-events/). However, it doesn't work on the first conditional statement, only the second (I've marked it in the code).
I hope you understand what I mean, and if you can help me with this, I'll be forever thankful.
- Gyro
edit: screwed up code
I'm trying to make a security system with a forcefield. the outside uses a terminal that needs to be unlocked with a password, while on the inside, I use a touch screen I activate to send off a rednet message to the first machine.
I've tried using a method from this forum (http://www.computerc...ultiple-events/). However, it doesn't work on the first conditional statement, only the second (I've marked it in the code).
I hope you understand what I mean, and if you can help me with this, I'll be forever thankful.
- Gyro
edit: screwed up code
local access = {
a = "Access Granted",
b = "Access Denied",
c = "Invalid"
}
function setText(color, x, y)
term.setTextColor(color)
term.setCursorPos(x, y)
end
local key2 = false
while key2 == false do
sleep(2)
rednet.open("left")
term.clear()
setText(colors.white, 1, 1)
write("Press any key to continue")
local event, p1, p2, p3 = os.pullEvent()
if event == "rednet_message" then --#THIS IS THE LINE THAT DOES NOT FIRE
local id = p1
local msg = p2
if msg == "1" and rs.getOutput("bottom") then
rs.setOutput("bottom", false)
elseif msg == "1" and not rs.getOutput("bottom") then
rs.setOutput("bottom", true)
end
elseif event == "key" then
term.clear()
setText(colors.white, 1, 1)
textutils.slowPrint("Welcome to ")
setText(colors.lime, 12, 1)
textutils.slowPrint("Gyro")
setText(colors.red, 16, 1)
textutils.slowPrint("Vault")
setText(colors.white, 21, 1)
print("!")
print(" ")
textutils.slowPrint("Please enter the admission code")
write("=>")
w, h = term.getSize()
local key1 = false
repeat
if read("*") == "ducky" then
sleep(1)
setText(colors.lime, (w-#access.a)/2, h/2)
write(access.a)
key1 = true
sleep(2)
term.clear()
else
sleep(1)
setText(colors.red, (w-#access.B)/>/2, h/2)
write(access.B)/>/>/>
sleep(2)
term.clear()
setText(colors.white, 1, 1)
textutils.slowPrint("Please enter the admission code")
write("=>")
end
until key1 == true
key2 = true
end
end
while true do
term.clear()
setText(colors.lime, 1, 1)
write("Gyro")
setText(colors.red, 5, 1)
write("Vault")
setText(colors.white, 1, 3)
if rs.getOutput("bottom") then
print("[1]Disable field")
print("[2]Lock")
print("[3]Disable field (5 sec)")
elseif not rs.getOutput("bottom") then
print("[1]Enable Field")
print("[2]Enable Field and Lock")
end
write("=>")
rednet.open("left")
local event, p1, p2, p3 = os.pullEvent()
if event == "char" then
local option = p1
if option == "3" and rs.getOutput("bottom") then
rs.setOutput("bottom", false)
sleep(5)
rs.setOutput("bottom", true)
elseif option == "1" and rs.getOutput("bottom") then
rs.setOutput("bottom", false)
elseif option == "2" and rs.getOutput("bottom") then
shell.run("test")
elseif option == "1" and not rs.getOutput("bottom") then
rs.setOutput("bottom", true)
elseif option == "2" and not rs.getOutput("bottom") then
rs.setOutput("bottom", true)
shell.run("test")
else
setText(colors.red, (w-#access.c)/2, h/2)
write(access.c)
end
elseif event == "rednet_message" then --#THIS LINE FIRES
local id = p1
local msg = p2
if msg == "1" and rs.getOutput("bottom") then
rs.setOutput("bottom", false)
elseif msg == "1" and not rs.getOutput("bottom") then
rs.setOutput("bottom", true)
end
shell.run("test")
end
end