Posted 19 April 2014 - 01:39 PM
I wrote a script that should output a redstone signal when the right code is entered on the touchscreen but when i start the script the monitor says "to index ? (a nil value)" but i don't know why!
password = 1598
count = 0
a = 0
b = 0
c = 0
d = 0
input = 0
access = 0
function Frame()
shell.run("clear")
term.setBackgroundColor(Colors.green)
term.setCursorPos(3,2)
print("123")
term.setCursorPos(3,3)
print("456")
term.setCursorPos(3,4)
print("789")
end
term.setBackgroundColor(Colors.black)
function Input()
while count < 4 do
event.side,x,y = os.pullEvent()
if event == "monitor_toch" then
if x == 3 and y == 2 then
if count == 1 then
a = 1
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 1
write("x")
elseif count == 3 then
c = 1
write("x")
elseif count == 4 then
d = 1
write("x")
end
end
if x == 4 and y == 2 then
if count == 1 then
a = 2
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 2
write("x")
elseif count == 3 then
c = 2
write("x")
elseif count == 4 then
d = 2
write("x")
end
end
if x == 5 and y == 2 then
if count == 1 then
a = 3
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 3
write("x")
elseif count == 3 then
c = 3
write("x")
elseif count == 4 then
d = 3
write("x")
end
end
if x == 3 and y == 3 then
if count == 1 then
a = 4
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 4
write("x")
elseif count == 3 then
c = 4
write("x")
elseif count == 4 then
d = 4
write("x")
end
end
if x == 4 and y == 3 then
if count == 1 then
a = 5
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 5
write("x")
elseif count == 3 then
c = 5
write("x")
elseif count == 4 then
d = 5
write("x")
end
end
if x == 5 and y == 3 then
if count == 1 then
a = 6
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 6
write("x")
elseif count == 3 then
c = 6
write("x")
elseif count == 4 then
d = 6
write("x")
end
end
if x == 3 and y == 4 then
if count == 1 then
a = 7
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 7
write("x")
elseif count == 3 then
c = 7
write("x")
elseif count == 4 then
d = 7
write("x")
end
end
if x == 4 and y == 4 then
if count == 1 then
a = 8
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 8
write("x")
elseif count == 3 then
c = 8
write("x")
elseif count == 4 then
d = 8
write("x")
end
end
if x == 5 and y == 4 then
if count == 1 then
a = 9
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 9
write("x")
elseif count == 3 then
c = 9
write("x")
elseif count == 4 then
d = 9
write("x")
end
end
end
end
count = 0
end
while true do
Frame()
Input()
input = (""..a..""..b..""..c..""..d.."")
access = (password-input)
if acces == 0 then
write("OK")
rs.setOutput("bottom", true)
sleep(0.5)
rs.setOutput("bottom", false)
else
write("FALSCH")
end
sleep(3)
term.setBackgroundColor(Colors.black)
end
password = 1598
count = 0
a = 0
b = 0
c = 0
d = 0
input = 0
access = 0
function Frame()
shell.run("clear")
term.setBackgroundColor(Colors.green)
term.setCursorPos(3,2)
print("123")
term.setCursorPos(3,3)
print("456")
term.setCursorPos(3,4)
print("789")
end
term.setBackgroundColor(Colors.black)
function Input()
while count < 4 do
event.side,x,y = os.pullEvent()
if event == "monitor_toch" then
if x == 3 and y == 2 then
if count == 1 then
a = 1
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 1
write("x")
elseif count == 3 then
c = 1
write("x")
elseif count == 4 then
d = 1
write("x")
end
end
if x == 4 and y == 2 then
if count == 1 then
a = 2
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 2
write("x")
elseif count == 3 then
c = 2
write("x")
elseif count == 4 then
d = 2
write("x")
end
end
if x == 5 and y == 2 then
if count == 1 then
a = 3
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 3
write("x")
elseif count == 3 then
c = 3
write("x")
elseif count == 4 then
d = 3
write("x")
end
end
if x == 3 and y == 3 then
if count == 1 then
a = 4
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 4
write("x")
elseif count == 3 then
c = 4
write("x")
elseif count == 4 then
d = 4
write("x")
end
end
if x == 4 and y == 3 then
if count == 1 then
a = 5
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 5
write("x")
elseif count == 3 then
c = 5
write("x")
elseif count == 4 then
d = 5
write("x")
end
end
if x == 5 and y == 3 then
if count == 1 then
a = 6
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 6
write("x")
elseif count == 3 then
c = 6
write("x")
elseif count == 4 then
d = 6
write("x")
end
end
if x == 3 and y == 4 then
if count == 1 then
a = 7
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 7
write("x")
elseif count == 3 then
c = 7
write("x")
elseif count == 4 then
d = 7
write("x")
end
end
if x == 4 and y == 4 then
if count == 1 then
a = 8
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 8
write("x")
elseif count == 3 then
c = 8
write("x")
elseif count == 4 then
d = 8
write("x")
end
end
if x == 5 and y == 4 then
if count == 1 then
a = 9
term.setBackgroundColor(Colors.black)
write("x")
elseif count == 2 then
b = 9
write("x")
elseif count == 3 then
c = 9
write("x")
elseif count == 4 then
d = 9
write("x")
end
end
end
end
count = 0
end
while true do
Frame()
Input()
input = (""..a..""..b..""..c..""..d.."")
access = (password-input)
if acces == 0 then
write("OK")
rs.setOutput("bottom", true)
sleep(0.5)
rs.setOutput("bottom", false)
else
write("FALSCH")
end
sleep(3)
term.setBackgroundColor(Colors.black)
end