[LUA] [SOLVED] Need to make MAX length and MIN length.
#1
Posted 04 April 2013 - 02:47 AM
#2
Posted 04 April 2013 - 03:01 AM
If so look in the APIs section of this forum, I seem to remember there being something that did this.
#3
Posted 04 April 2013 - 03:08 AM
local pass = read("*")
if #pass < 2 then
print("Password too short")
elseif #pass > 10 then
print("You want to be really secure, but this is too long.")
end
#5
Posted 04 April 2013 - 03:12 AM
Example :
local input = nil local minLength = 2 local maxLength = 10 while (input == nil or #input < minLength or #input > maxLength) do input = read() end
I think it should work as you expect.
#6
Posted 04 April 2013 - 03:14 AM
Ninetainedo, on 04 April 2013 - 03:12 AM, said:
Example :
local input = nil local minLength = 2 local maxLength = 10 while (input == nil or #input < minLength or #input > maxLength) do input = read() end
I think it should work as you expect.
No that won't because then you would have to type a char and hit enter before you can go on and you have no way to do a backslash.
It is possible but not that easy.
#7
Posted 04 April 2013 - 03:20 AM
JokerRH, on 04 April 2013 - 03:14 AM, said:
Ninetainedo, on 04 April 2013 - 03:12 AM, said:
Example :
local input = nil local minLength = 2 local maxLength = 10 while (input == nil or #input < minLength or #input > maxLength) do input = read() end
I think it should work as you expect.
No that won't because then you would have to type a char and hit enter before you can go on and you have no way to do a backslash.
It is possible but not that easy.
I don't understand why it shouldn't work. I modified it and tried, it seems to work as expected :
local input = nil
local minLength = 2
local maxLength = 10
while (input == nil) do
write("Pass : ")
input = read()
if (#input < minLength or #input > maxLength) then
print("Enter between "..minLength.." and "..maxLength.." characters please.")
input = nil
end
end
#8
Posted 04 April 2013 - 03:40 AM
though you dont need "= nil" on the first line
local input is enough
and you can simplify that while statement:
while not input doanything not nil or false will pass as true on statements like these
#9
Posted 04 April 2013 - 03:45 AM
I use to write
while (not input) doWhen input is supposed to be false. When I want to check if it is nil, I prefer write it clearly. It's just because I am a C programer, I guess ! ^^
#10
Posted 04 April 2013 - 03:45 AM
It still lets the users input nothing. How can I stop this?
#11
Posted 04 April 2013 - 03:49 AM
user = nil
user = read()
if #user == 0 then
term.setCursorPos(16,15)
term.write("User Name Cannot Be Empty!")
new()
else
new()
end
#12
Posted 04 April 2013 - 03:50 AM
an empty string isnt nil
replace
if pass == nil thenwith:
if pass == "" then
Ninetainedo's method works too
EDIT:
you seem to be using recursion also .-.
please dont call functions within itself, that causes problems
use loops instead or else the program will stack overdflow after awhile
#13
Posted 04 April 2013 - 04:02 AM
PixelToast, on 04 April 2013 - 03:50 AM, said:
you seem to be using recursion also .-.
please dont call functions within itself, that causes problems
use loops instead or else the program will stack overdflow after awhile
As just said Pixel, you shouldn't use recursion because of stack overflow.
I just want to quote the Codex of Error slaying (http://www.computerc...laying-2/#AIOOB) which says that:
Quote
function asd() return asd() end
If you do so, you won't have any stack overflow.
But, as said Pixel, you should use loops instead of recursion. I just say it because it doesn't represent a lot of changes in your code and it solves the stack issues.
You just have to put return before your recursive call.
return new()
#14
Posted 04 April 2013 - 04:05 AM
#15
Posted 04 April 2013 - 04:11 AM
elseif button == 1 and x >= LXmin and x <= LXmax and y >= LYmin and y <= LYmax then
You actually don't check your pass and user variables. If you want to show an error message, you have to check them.
Edit:
Moreover, I think you should put your variables before your function or, at least, before your first if.
#16
Posted 04 April 2013 - 04:14 AM
Ninetainedo, on 04 April 2013 - 04:11 AM, said:
elseif button == 1 and x >= LXmin and x <= LXmax and y >= LYmin and y <= LYmax then
You actually don't check your pass and user variables. If you want to show an error message, you have to check them.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











