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
to index ? (a nil value) ERROR
Started by Masy, Apr 19 2014 12:39 PM
2 replies to this topic
#1
Posted 19 April 2014 - 12:39 PM
#2
Posted 20 April 2014 - 07:28 PM
Masy, on 19 April 2014 - 12:39 PM, said:
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!
A quick review of your code uncovered a couple of obvious errors.
You have
if event == "monitor_toch" then
It should be
if event == "monitor_touch" then
You are also capitalizing the word 'colors' when you are assigning colors. This is incorrect and will not work. Proper capitalization, punctuation, and spelling in programming are not optional. Apologies if that sounds harsh (that isn't the intention), but you'll have far fewer problems if you aren't constantly chasing down errors like this - it pays to be more careful. Remember - computers don't do what you want them to do, only what you tell them to do.
A couple other things of note:
- You should localize your variables when you first declare them. I localized the first two as an example.
- Please use CODE tags when posting code - it makes it much easier to read.
- Please include the FULL error message. The error message you posted was incomplete and is missing critical information
Once you make those corrections, test the code and we'll proceed from there.
local password = 1598
local 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
Edited by Dog, 20 April 2014 - 08:42 PM.
#3
Posted 20 April 2014 - 07:33 PM
meanwhile, the actual compilation error is
since the color api is called "color", not "Color".
Post the error line next time.
term.setBackgroundColor(Colors.black)
Post the error line next time.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











