Jump to content

why isn't this working (gui)


Recommended Posts

The validName(theText) doesn't return as true....

function validName(theText)
local foundSpace, valid = false, true
local spaceBefore = false
local current = ''
for i = 1, #theText do
local char = theText:sub( i, i )
if char == ' ' then -- it's a space
if i == #theText or i == 1 or spaceBefore then -- space at the end or beginning or two spaces are not allowed
			valid = false
break
end
		current = ''
		spaceBefore = true
elseif ( char >= 'a' and char <= 'z' ) or ( char >= 'A' and char <= 'Z' ) then -- can have letters anywhere in the name
		current = current .. char
		spaceBefore = false
else -- unrecognized char (special chars)
		valid = false
break
end
end
 
if valid  and #theText < 'Z' then
return true
else
return false
end
end
 
 
 
 
function checkNameBox()
if (source==NameBox) then
local theText = guiGetText(source)
 
if validName(theText) then
		GUIEditor_Label[1] = guiCreateLabel(80,157,204,21,"- Must Be Firstname Lastname format",false,creationWin)
guiLabelSetColor(GUIEditor_Label[1], 0, 255, 0)
		GUIEditor_Label[2] = guiCreateLabel(80,173,204,21,"- Can not exceed 20 characters",false,creationWin)
guiLabelSetColor(GUIEditor_Label[2], 0, 255, 0)
		GUIEditor_Label[3] = guiCreateLabel(82,206,204,21,"- Must be realistic",false,creationWin)
guiLabelSetColor(GUIEditor_Label[3], 0, 255, 0)
		GUIEditor_Label[4] = guiCreateLabel(81,190,204,21,"- Can not be a celebrity's name",false,creationWin)
guiLabelSetColor(GUIEditor_Label[4], 0, 255, 0)
		GUIEditor_Label[5] = guiCreateLabel(82,222,275,21,"- Can not have the same last name unless related",false,creationWin)
guiLabelSetColor(GUIEditor_Label[5], 0, 255, 0)
		GUIEditor_Label[6] = guiCreateLabel(82,239,275,21,"- May only contain letters",false,creationWin)
guiLabelSetColor(GUIEditor_Label[6], 0, 255, 0)
else
		GUIEditor_Label[1] = guiCreateLabel(80,157,204,21,"- Must Be Firstname Lastname format",false,creationWin)
guiLabelSetColor(GUIEditor_Label[1], 255, 0, 0)
		GUIEditor_Label[2] = guiCreateLabel(80,173,204,21,"- Can not exceed 20 characters",false,creationWin)
guiLabelSetColor(GUIEditor_Label[2], 255, 0, 0)
		GUIEditor_Label[3] = guiCreateLabel(82,206,204,21,"- Must be realistic",false,creationWin)
guiLabelSetColor(GUIEditor_Label[3], 255, 0, 0)
		GUIEditor_Label[4] = guiCreateLabel(81,190,204,21,"- Can not be a celebrity's name",false,creationWin)
guiLabelSetColor(GUIEditor_Label[4], 255, 0, 0)
		GUIEditor_Label[5] = guiCreateLabel(82,222,275,21,"- Can not have the same last name unless related",false,creationWin)
guiLabelSetColor(GUIEditor_Label[5], 255, 0, 0)
		GUIEditor_Label[6] = guiCreateLabel(82,239,275,21,"- May only contain letters",false,creationWin)
guiLabelSetColor(GUIEditor_Label[6], 255, 0, 0)
end
end
 
end

Link to comment

I'll give you advice for if statements. Use brackets ( "(" and ")" ) to separate checks because in Lua or and and have unexpected results.

You may thing that it should work but it doesn't, after you add brackets it works. Well, at least that what I noticed one day.

For instance look at this example and ask yourself what the result you'd expect:

a = 2
b = 1
c = 3
d = 4
 
e = a > b or c and d -- what do you think e will be?
 
e = a < b or c and d -- what do you think e will be?

In the first case, e will be true,

In the second case, e will be 4

Do you see what I mean now? Well, if you think about these 2, it makes sense but if you don't, you may end up with unexpected results. I'd advice you use them. It doesn't cost you anything but they are used in other languages and it's good to get used to them earlier.

Brackets return true or false but or and and may return values that you don't want.

So, one of your if statements would be:

if ( ( i == #theText ) or ( i == 1 ) or ( spaceBefore ) ) then

I'm not saying this is a bug in your script though. You should debug your function and check where the loop breaks or where it returns false and you'll find out why it returns false every time. If you will debug it and won't find out anything just tell us where the function returns or loop breaks.

What's the point of current in this function? It's only assigned new values, nothing else.

Link to comment

well the point is to create a guiEdit that requires the input to resemble Firstname Lastname format and when it does not the text on the guiWindow goes red and the next button becomes unclickable until the user fixes his/her mistake which then will turn the text green and the next button will then become clickable

Link to comment
still nothing :? I placed parenthesis in the according spots but it still doesn't act how I want it to
...

I'm not saying this is a bug in your script though. You should debug your function and check where the loop breaks or where it returns false and you'll find out why it returns false every time. If you will debug it and won't find out anything just tell us where the function returns or loop breaks.

What's the point of current in this function? It's only assigned new values, nothing else.

Link to comment
still nothing :? I placed parenthesis in the according spots but it still doesn't act how I want it to
...

I'm not saying this is a bug in your script though. You should debug your function and check where the loop breaks or where it returns false and you'll find out why it returns false every time. If you will debug it and won't find out anything just tell us where the function returns or loop breaks.

What's the point of current in this function? It's only assigned new values, nothing else.

well the point is to create a guiEdit that requires the input to resemble Firstname Lastname format and when it does not the text on the guiWindow goes red and the next button becomes unclickable until the user fixes his/her mistake which then will turn the text green and the next button will then become clickable
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...