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

Problem

Started by ryanjr, 11 September 2013 - 09:13 PM
ryanjr #1
Posted 11 September 2013 - 11:13 PM
I made a program and I've been trying to fix it. Please help. Heres the code that should work but doesn't.

term.clear()
term.setCursorPos(1,1)
textutils.slowWrite("Hello, please login.")
sleep(2)
term.clear()

term.setCursorPos(1,1)
print("username: ")

local U = read()
if U == ryanjr then
print(U.." is correct")
sleep(1)
else
print(U.." is incorrect. Try again")
sleep(1)
os.reboot()
end

This is only the beginning of the code, the part that doesn't work. Please help.
Lyqyd #2
Posted 11 September 2013 - 11:32 PM
Please read the sticky topic "Please Read Before Asking Questions".

Your question has a number of problems. You didn't give us the whole code. You didn't state what was wrong, or what the error was. You simply said it "doesn't work" with no further explanation. You didn't say how you know it doesn't work. You didn't say what it's supposed to do. You didn't say what it does instead.

In spite of all of that, I can clearly see that the issue is that you forgot the quotes around a string literal. Change your if statement to include quotes:


if U == "ryanjr" then
bigbaddevil6 #3
Posted 12 September 2013 - 03:58 AM
May i suggest using a loop instead of an os.reboot(). Like with what lyqyd said about posting, i don't know what this code is used for, but say for instance its just a password to open a door. All you would need to do is put the code inside a while loop and it will do the same thing. Plus with doing it like that you can have the person enter the password if its wrong then all it does is have them enter it again instead of having the computer restart and rerun the whole program. The You wouldn't have your real computer restart every time you entered in your username.
ryanjr #4
Posted 13 September 2013 - 08:11 PM
Thank you both of you. That should work and from now on I will use the full topic curriculum.