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

Multiple User Program Help

Started by Mothraa, 27 February 2012 - 03:57 AM
Mothraa #1
Posted 27 February 2012 - 04:57 AM
Made this simple user program for my guild, but it seems to get stuck at the username screen. Probably a small error in my code thats making it not recognize the usernames. I couldn't figure it out after about 45 minutes, so I posted it here.

The Code:
http://pastebin.com/pQtYMhzb
Liraal #2
Posted 27 February 2012 - 06:01 AM
idk whether it's your problem, but try: if read() == pass0 then
Luanub #3
Posted 27 February 2012 - 07:58 AM
Try this..

Replace:

write "nUsername: "
if read() == user0 then

with something like:

write ("Username: ")
local uname = read()
    if uname == user0 then
		 user0()
    elseif uname == user1 then
	   user1()

and so on for each user
Mothraa #4
Posted 27 February 2012 - 08:11 PM
I updated it to your specifications, but it still goes straight to the else argument in the function.

http://pastebin.com/tXg9qUfg
Liraal #5
Posted 27 February 2012 - 09:01 PM
shell.run"shell" What is this part for?
you forgot about brackets. every lua function has them
so it'd be like print(whatever) not print whatever .
Mothraa #6
Posted 27 February 2012 - 09:13 PM
That doesn't exactly solve the problem.
If you try running the program without brackets it works perfectly fine. I added them to be sure, not a single difference.
The shell.run"shell" brings up the CraftOS 1.3 text, you know whenever you first startup the computer.
Thanks anyways. :P/>/>
Luanub #7
Posted 27 February 2012 - 09:41 PM
You need to update your password scripting as well.


write "nPassword: "
if read("*") == pass1 then
open()

to

write ("Password: ")
local passwd = read("*")
if passwd == pass1 then
open()
and so on...

If you still have problems let me know and ill look a little deeper into the rest of the code, from a glance it looks ok.

Always keep in mind with stuff like read() and some of the system events its always best to capture the input as a var then do your checking.
Mothraa #8
Posted 27 February 2012 - 11:08 PM
Thank you for the help so far, but the same problem still occurs. <_</>/>
It works up to where it asks for the username, I type in any of the usernames and it brings up "Username Does Not Exist." then takes me back to the user function like it's supposed to, only those usernames do exist and therefore should be continuing on to the matching user password function.

Updated Code: http://pastebin.com/EFMdWw1k
MysticT #9
Posted 27 February 2012 - 11:35 PM
Well, it was a little hard to find, but i found the error.
You define the variables user0, user1 and user2, and then define functions with the same name, so when you do the comparison it compares the input with the functions, wich will never be the same (string != function).
Change the names of the variables or the functions and it should work <_</>/>
Mothraa #10
Posted 27 February 2012 - 11:42 PM
Well I just learned something new today, thank you, MysticT and luanub! <_</>/>