1 posts
Posted 25 May 2014 - 11:50 AM
So I made this lock on computercraft and for some reason I can't get it to work?
The lock is:
while true do
term.clear ()
term.setCursorPos (1, 1)
print ("Please Enter Door Code:")
lacal input = read("*")
if input == "pass" then
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false)
else
print ("Code is incorrect!")
sleep(2)
os.shutdown
end
end
However, when I reboot the computer in order to start it, it says
"reboot:3: attempt to call nil
I have no idea what it means so any help would be much appreciated.
227 posts
Location
Germany
Posted 25 May 2014 - 01:28 PM
First of all in line 5, replace lacal with local (I think you didn't copy, but wrote it to the forums by hand).
Also in line 13 you forgot the () for os.shutdown().
Other than that your code should work perfectly.
(You can leave out os.shutdown(), because your code is already in an endless loop.)
Next time, please use code tags(the <> symbol in the editor)and put your code in there.
Edited on 25 May 2014 - 11:29 AM
1852 posts
Location
Sweden
Posted 25 May 2014 - 11:05 PM
Next time, please use code tags(the <> symbol in the editor)and put your code in there.
or just write
[!CODE] This will be some code [!/CODE] ( without the '!' )
63 posts
Posted 25 May 2014 - 11:23 PM
Fixed formatting:
while true do
term.clear ()
term.setCursorPos (1, 1)
print ("Please Enter Door Code:")
lacal input = read("*")
if input == "pass" then
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false)
else
print ("Code is incorrect!")
sleep(2)
os.shutdown
end
end
Debugging:
Line 5: It's local, not lacal.
Line 13: os.shutdown is incorrect. Try os.shutdown()
Also, consider changing your code to:
while true do
term.clear ()
term.setCursorPos (1, 1)
print ("Please Enter Door Code:")
local input = read("*")
if input == "pass" then
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false)
else
print ("Code is incorrect!")
sleep(2)
-- Code that was changed is here... Unneeded....
end
end
227 posts
Location
Germany
Posted 26 May 2014 - 03:04 PM
-snip-
I wonder if you even read my post. (I wrote the exact same thing 10 hours before)