8 posts
Posted 04 April 2014 - 11:19 PM
Ive been having problems with my login system code. Out of my knowledge, I think this should work.
term.clear()
term.setCursorPos(1, 1)
username = {"andrew28", "nhutnguyen1234"}
password ={"nga64AT@", "dragon29"}
write("Username: ")
user = read()
write("Password: ")
pass = read ('*')
for i=1, #username do
if user == username[i] and pass == password[1] then
access = true
end
end
if access == true then
print("Logging in...")
sleep(1)
print("Welcome "..user)
else
print("Incorrect Credits")
sleep(2)
os.reboot()
end
It only happens when I enter incorrect credits.
Edited on 04 April 2014 - 09:20 PM
21 posts
Posted 04 April 2014 - 11:32 PM
I'm unable to test at this moment so sorry if I'm wrong but shouldn't password[1] be password[i] in the first if? If not, what is the problem exactly?
Edited on 04 April 2014 - 09:33 PM
1281 posts
Posted 04 April 2014 - 11:46 PM
I'm unable to test at this moment so sorry if I'm wrong but shouldn't password[1] be password[i] in the first if? If not, what is the problem exactly?
This is probably correct, however it wouldn't cause the aformentioned error.
Your error points to line 26, the code you posted is 22 lines. Please post the full code.
21 posts
Posted 04 April 2014 - 11:53 PM
Oops yeah, the title eluded me.
350 posts
Posted 05 April 2014 - 02:20 PM
I think that the problem isnt in your code but maybe in the default startup code.. did you changed anything in there?
8 posts
Posted 05 April 2014 - 02:39 PM
I didn't do anything to it. I don't know what happened here
7083 posts
Location
Tasmania (AU)
Posted 05 April 2014 - 03:34 PM
Presumably this IS your startup code y/n?
What happens if you just trying running os.reboot() via the Lua prompt?
8 posts
Posted 06 April 2014 - 04:41 PM
It doesn't work, shutdown works though. Im gonna use shell.exit
350 posts
Posted 06 April 2014 - 05:02 PM
my cc has be going wierd just like that… it prints out errors in a perfect code (when i try do call a function) and the problem may be in you cc not in the code. Try reinstalling cc.
1281 posts
Posted 06 April 2014 - 05:45 PM
Ugh this went off the rails so fast…
Your error points to line 26, the code you posted is 22 lines. Please post the full code.
1852 posts
Location
Sweden
Posted 06 April 2014 - 07:04 PM
Uhmm.. Try to declare the variable
access like this above all of your code and see if that solves anything
local access = false
If this isn't all of your code then please do as CometWolf above me said and post the full code.
350 posts
Posted 06 April 2014 - 08:01 PM
I had the chance, to try out this code, and it works perfectly. You may have a conflict with other codes(so as everyone said, paste here your full code) or you may have a bug in your minecraft/computercraft/forge (try reinstalling them)