This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
UnforgivingOne's profile picture

Lua programming problem. (locked door code)

Started by UnforgivingOne, 07 March 2013 - 04:22 AM
UnforgivingOne #1
Posted 07 March 2013 - 05:22 AM
Hello! I've been working on a code, the goal is to make a password protected door. (combined with redpower2 framed motors)
right now I am not sure what is wrong. But this is the message I get (When either entering the password or debug password): Startup:10: Attempt to call nil

Here's the code:



term.clear()
term.setCursorPos( 1, 1 )

password = "cheese"
debug = "admin"
write("Enter your password: ")
input = read()

term.clear()
term.setCursorPos( 1, 1 )
if input == password then
print("Password Accepted!")
rs.setBundledOutput( "back", 0 )
sleep(0.25)
rs.setBundledOutput( "back", 2 )
sleep(0.5)
rs.setBundledOutput( "back", 0 )
sleep(0.5)
rs.setBundledOutput( "back", 2 )
sleep(0.25)
rs.setBundledOutput( "back", 0 )
sleep(5)
rs.setBundledOutput( "back", 1 )
sleep(0.5)
rs.setBundledOutput( "back", 0 )
sleep(0.5)
rs.setBundledOutput( "back", 1 )
sleep(0.25)
rs.setBundledOutput( "back", 0 )
os.shutdown()

elseif input == debug
then
exit()

else
print("Password Incorrect!")
sleep(2)
os.shutdown()
end
Edited by
Lyqyd #2
Posted 07 March 2013 - 06:37 AM
Split into new topic.
UnforgivingOne #3
Posted 07 March 2013 - 07:23 AM
Figured it out!
Mistake I corrected here but not when inputting it into my program in-game. at line 10: term.setCursorpos( 1 , 1 )
I had term.setCursospos

So the code put on here should work perfectly :)/>
Frederikam #4
Posted 07 March 2013 - 07:27 AM
Figured it out!
Mistake I corrected here but not when inputting it into my program in-game. at line 10: term.setCursorpos( 1 , 1 )
I had term.setCursospos

So the code put on here should work perfectly :)/>
I'll just explain to you that "attempt to call nil" means that you are trying to call a function that doesn't exist, such as term.setCursospos(). ":10:" means the error occurred at line 10.
Engineer #5
Posted 07 March 2013 - 07:35 AM
Lol was like: whats not working.. just tested it ^.^
remiX #6
Posted 07 March 2013 - 07:35 AM
Figured it out!
Mistake I corrected here but not when inputting it into my program in-game. at line 10: term.setCursorpos( 1 , 1 )
I had term.setCursospos

So the code put on here should work perfectly :)/>

Yeah, thought so - I couldn't find any problems with the posted code… :P/>
UnforgivingOne #7
Posted 07 March 2013 - 07:39 AM
Figured it out!
Mistake I corrected here but not when inputting it into my program in-game. at line 10: term.setCursorpos( 1 , 1 )
I had term.setCursospos

So the code put on here should work perfectly :)/>

Yeah, thought so - I couldn't find any problems with the posted code… :P/>

Oh the awkward mistakes we do :P/>
On to improving and expanding this one then! :)/>
UnforgivingOne #8
Posted 07 March 2013 - 07:40 AM
Figured it out!
Mistake I corrected here but not when inputting it into my program in-game. at line 10: term.setCursorpos( 1 , 1 )
I had term.setCursospos

So the code put on here should work perfectly :)/>
I'll just explain to you that "attempt to call nil" means that you are trying to call a function that doesn't exist, such as term.setCursospos(). ":10:" means the error occurred at line 10.

thanks! I partially figured that out after awhile :)/>
How am I doing by the way? Started learning computercraft yesterday evening, and this is what I've done in between school & homework :)/>
diegodan1893 #9
Posted 07 March 2013 - 08:28 AM
To exit a program you don't need to add the "debug" line, just hold Ctrl + T and it will terminate the program. To prevent this (if your program is a password loock) put in the first line of your program:

os.pullEvent = os.pullEventRaw

This works because Ctrl + T causes an error that is handled in os.pullEvent() function, but not in os.pullEventRaw(). As read() uses os.pullEvent you can terminate the program, but functions work as variables if you don't write '()' so you can make os.pullEvent works in the same way as os.pullEventRaw does. Hope this helps.
UnforgivingOne #10
Posted 07 March 2013 - 08:49 AM
To exit a program you don't need to add the "debug" line, just hold Ctrl + T and it will terminate the program. To prevent this (if your program is a password loock) put in the first line of your program:

os.pullEvent = os.pullEventRaw

This works because Ctrl + T causes an error that is handled in os.pullEvent() function, but not in os.pullEventRaw(). As read() uses os.pullEvent you can terminate the program, but functions work as variables if you don't write '()' so you can make os.pullEvent works in the same way as os.pullEventRaw does. Hope this helps.

Yes, thank you! :)/> I have already read abit about that, but the debug line is basically like a back door for me, so I can access the computer and do whatever I want to do. however when the code is just like it is right now, without the "os.pullEvent = os.pullEventRaw" you can not use ctrl + T to exit the program and gain access to the computer. so I like the way it is now, but I will without a doubt keep this in mind for later use!
Lyqyd #11
Posted 07 March 2013 - 10:20 AM
however when the code is just like it is right now, without the "os.pullEvent = os.pullEventRaw" you can not use ctrl + T to exit the program and gain access to the computer. so I like the way it is now, but I will without a doubt keep this in mind for later use!

This is entirely false. Pressing and holding Ctrl-T while this program, as it currently stands, is waiting in the read prompt, or in any of the sleep calls, would terminate the program.