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

Login system

Started by shwb1, 20 October 2012 - 08:55 PM
shwb1 #1
Posted 20 October 2012 - 10:55 PM
Ok so after running around finding help where i need it, i came to a issue

term.clear()
term.setCursorPos(1,1)
print("Please insert your username and password")
print("User:")
print("Password:")

local choice = 1

term.setCursorPos(6,2)

while true do
local e,e1,e2,e3,e4,e5 = os.pullEvent()
if e == "key" then
if e1 == 200 then
if choice == 2 then
choice = 1
else
choice = choice+1
end
end
if e1 == 208 then
if choice == 1 then
choice = 2
else
choice = choice-1
end
end
if e1 == 14 then
term.clearLine()
if choice == 1 then
term.setCursorPos(1,2)
write("User:")
end
if choice == 2 then
term.setCursorPos(1,3)
write("Password:")
end
end
if choice == 1 then
term.setCursorPos(6,2)
if username == "" then
username = read()
else
username = ""
username = read()
end
if choice == 2 then
term.setCursorPos(10,3)
if password == "" then
password = read()
else
password = ""
password = read()
end
end
end
end
end

This script is spost to ask for a user name, and when they press up or down it would select
the username or password input, and when you typed it it would save it in a var if username
or password already had a input and you pressed backspace while having one selected it would
clear it, but now im stuck, it wont let me type in the space like before so if i selected user
it would not let me type there even if i pressed backspace can someone help?
jag #2
Posted 20 October 2012 - 11:10 PM
Could you surround you code with
tags? It would be much easier to read then.
It would also help if you post this on pastebin or something similar!
jag #3
Posted 20 October 2012 - 11:11 PM
And btw, os.pullEvent() will only return 4 values:
  1. Event name.
  2. Parameter 1.
  3. Parameter 2.
  4. Parameter 3.
jag #4
Posted 20 October 2012 - 11:16 PM
Now I notice that you got that fancy selecting system, but you are still using read()
And as a tip: if you give read() a value the characters will look like that value.
For example if you do password = read("*") then when you type it will show up as "stars".
This would be helpful so that no-one can see your password while you're typing (if you are on a server).
shwb1 #5
Posted 20 October 2012 - 11:20 PM
ok but what about my problem? it wont read where you type
jag #6
Posted 20 October 2012 - 11:23 PM
Ah I can see that you've added code tags.
But you'll have to add an ending tag.
Its actually the same but just with a / after the first [.

So for example:
(Without the stars)
[code*] Hi there [/code*]

Will result like
 Hi there 
shwb1 #7
Posted 20 October 2012 - 11:23 PM
btw i am semi-new, ive coded for around a half-year a few years ago, then lost my computer for awhile and when i got it back i completely forgot about lua, so its been awhile since i coded im plucking info from my brain and google to help me :)/>/>

EDIT:
Yeah i forgot the / but i edited it right after :S you are fast to catch it right when i edit it
jag #8
Posted 20 October 2012 - 11:35 PM
Now, lets get back on-topic :)/>/>

So I don't really know what your problem is…
What I've got so far is that you can choose to enter username or password, and when you got the selection you want you press enter to start typing in the username/password. But this is where you get stuck and can't do anything.
Correct me if I'm wrong
shwb1 #9
Posted 20 October 2012 - 11:37 PM
yes that is completely right, you select your username or password and when you want to type it wont let you
remiX #10
Posted 20 October 2012 - 11:49 PM
I'm not quite understanding your question/problem too o,O

Btw, please indent your code so its easier to read =p
shwb1 #11
Posted 20 October 2012 - 11:56 PM
what do you mean by indent?
jag #12
Posted 20 October 2012 - 11:59 PM
No indent:

if something == "thingy" then
print("Its something")
if thingy == "milk" then
print("Cow time!")
end
end

Indent:

if something == "thingy" then
    print("Its something")
    if thingy == "milk" then
        print("Cow time!")
    end
end
Lyqyd #13
Posted 21 October 2012 - 12:01 AM
You've got your if choice == 2 inside your if choice == 1, so it can't ever get to the read() for the password. Check your end placements.
ChunLing #14
Posted 21 October 2012 - 12:04 AM
Indented.
Spoiler
term.clear()
term.setCursorPos(1,1)
print("Please insert your username and password")
print("User:")
print("Password:")

local choice = 1

term.setCursorPos(6,2)

while true do
	local e,e1,e2,e3,e4,e5 = os.pullEvent()
	if e == "key" then
		if e1 == 200 then
			if choice == 2 then
				choice = 1
			else
				choice = choice+1
			end
		end
		if e1 == 208 then
			if choice == 1 then
				choice = 2
			else
				choice = choice-1
			end
		end
		if e1 == 14 then
			term.clearLine()
			if choice == 1 then
				term.setCursorPos(1,2)
				write("User:")
			end
			if choice == 2 then
				term.setCursorPos(1,3)
				write("Password:")
			end
		end
		if choice == 1 then
			term.setCursorPos(6,2)
			if username == "" then
				username = read()
			else
				username = ""
				username = read()
			end
			if choice == 2 then
				term.setCursorPos(10,3)
				if password == "" then
					password = read()
				else
					password = ""
					password = read()
				end
			end
		end
	end
end
Spoiler tags are nice too, they make threads more readable. Put them in like so:
[spoiler][/spoiler]
shwb1 #15
Posted 21 October 2012 - 12:15 AM
With indents >
Spoiler

term.clear()
term.setCursorPos(1,1)
print("Please insert your username and password")
print("User:")
print("Password:")

local choice = 1

term.setCursorPos(6,2)

while true do
	local e,e1,e2,e3,e4,e5 = os.pullEvent()
	if e == "key" then
		if e1 == 200 then
			if choice == 2 then
				choice = 1
			else
				choice = choice+1
			end
		end
		if e1 == 208 then
			if choice == 1 then
				choice = 2
			else
				choice = choice-1
			end
		end
		if e1 == 14 then
			term.clearLine()
			if choice == 1 then
				term.setCursorPos(1,2)
				write("User:")
			end
			if choice == 2 then
				term.setCursorPos(1,3)
				write("Password:")
			end
		end
	end
	if choice == 1 then
		term.setCursorPos(6,2)
		if username == "" then
			username = read()
		else
			username = ""
			username = read()
		end
	end
	if choice == 2 then
		term.setCursorPos(10,3)
		if password == "" then
			password = read()
		else
			password = ""
			password = read()
		end
	end
end
jag #16
Posted 21 October 2012 - 12:15 AM
Indented.
Spoiler–snapped code–
Spoiler tags are nice too, they make threads more readable. Put them in like so:
[spoiler][/spoiler]
I wouldn't say more readable, more like more user friendly. But mostly; yes
Lyqyd #17
Posted 21 October 2012 - 12:16 AM
I see you've rearranged your if statements. Did that resolve the problem asking for the password?

Edit: jag, yes, indenting code properly greatly improves the readability of that code.
shwb1 #18
Posted 21 October 2012 - 12:17 AM
i think i may of fixed it myself :)/>/> after searching for what lyqyd said, and indenting, i need to test it tho :)/>/>
EDIT:
yup i fixed it :)/>/> thanks for your help guys :)/>/>
the problem was, when it was checking for a key it didnt have a end, i probably misplaced it at the end :/
ChunLing #19
Posted 21 October 2012 - 04:18 AM
I think that jag was talking bout the spoiler tags. Personally, I find that long code posts make it hard to track the flow of the discussion. Also, if you are reading one code and you page down and find yourself in another, different code, then that can be pretty confusing. So I find it a lot easier to only look at the code when I want to. A code that is less than about half a page is different, you can see the context and easily see that it isn't part of another code.