ID:139787
 
Code:
mob
Login()
icon='ICONS.dmi'
world<<"<font color = purple>[src.name] has logged in!"
var/obj/Z=input("Male or Female?")in list("Male","Female")
if(Z=="Male")
src.icon_state="Player_male"
if(Z=="Female")
src.icon_state="Player_female"
var/obj/X=input("What do you want your name to be?(At least 4 letters. 12 Letters or under. No innappropriate names allowed. No numbers or symbols. No spaces.)")
if(length(text) + 12 == X)
src<<"That name is too long."
return
if(length(text) - 4 == X)
src<<"That name is too short."
return
if(findtext(X,"1"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"2"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"3"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"4"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"5"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"6"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"7"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"8"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"9"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"0"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"~"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"`"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"!"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"@"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"#"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"$"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"%"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"^"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"&"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"*"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"("))
src<<"Your name has an invalid character in it."
return
if(findtext(X,")"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"-"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"_"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"="))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"+"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"{"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"}"))
src<<"Your name has an invalid character in it."
return
if(findtext(X," "))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"|"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"'"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"/"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"?"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,";"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,":"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"."))
src<<"Your name has an invalid character in it."
return
if(findtext(X,">"))
src<<"Your name has an invalid character in it."
return
if(findtext(X,","))
src<<"Your name has an invalid character in it."
return
if(findtext(X,"<"))
src<<"Your name has an invalid character in it."
return
if(X=="Maltan")
src<<"You can't have the same name as an NPC!"
return
if(X=="Mary")
src<<"You can't have the same name as an NPC!"
return
if(X=="Jarven")
src<<"You can't have the same name as an NPC!"
return
if(X=="Marcus")
src<<"You can't have the same name as an NPC!"
return
src.name="[X]"
src.charname="[X]"


Problem description: Well, this blocks it well enough when a player tries to use any of these characters, but the return proc doesn't bring them back to the name option... anyone know why?

Because you aren't telling it to return to the name input. Use a while loop.

Here's a much better way of handling what you are trying to do. It checks the characters against acceptable ranges of values, instead of searching for every single possible violation explicitly.

Not only will the example below look cleaner, it will be faster than your method.

var/nameallowed = 0
var/tchar = 0
var/tname
while(!nameallowed)
nameallowed = 1 //temporarily set this to true.
tname = input(src,"Please enter a name. Only letters, numbers, and spaces are accepted.","Name") as text
for(var/c=1;c<=length(tname);c++) //run through the entire name string
tchar = text2ascii(tname,c) //store the ascii character at the current position
if(tchar>=48&&tchar<=58) //allow numbers
continue //move on to the next character
else if(tchar>=65&&tchar<=90) //allow capital letters
continue
else if(tchar>=97&&tchar<=122) //allow lowercase letters
continue
else if(tchar==32) //allow spaces
continue
//if the character is not acceptable.
nameallowed = 0 //we now know the name isn't allowed
alert(src,"Your name must consist only of numbers, spaces, and letters. You will be asked to enter your desired name again until you comply with these rules.","Name invalid","OK") //warn them
break //terminate the loop
src.name = tname
In response to Ter13
Like so:

mob/Login()
var/selected_name
do
selected_name = input()
while(!is_valid_name(selected_name))
// etc.

proc
is_valid_name(var/name)
if(name is invalid)
return 0
return 1
In response to Ter13
I made all the 'return's to 'return X's.
In response to Colin1011
See my original post. I was charitable enough to give you a better example of this system.

Also, it's pretty clear you didn't read what I said. I didn't say anything about returning X, and told you to use a while loop.
In response to Colin1011
Colin1011 wrote:
I made all the 'return's to 'return X's.

Yup. That's a thing that will do nothing, here.