ID:144515
 
Code:
    newchar2()
char_name
var/user_name = input(usr, "Your name?", "Name")
if(!user_name)
goto char_name
if(lentext(user_name) > 20)
usr <<"<font size = 1><font color = red><b>System:</b></font><font size = 1><font color = black><b> Your name is too long.</b></font>"
goto char_name
for(var/N in un_wanted_names && html)
if(findtext(user_name,N))
usr<<"<font size = 1><font color = red><b>System:</b></font><font size = 1><font color = black><b> Please do not put HTML in names.</b></font>"
goto char_name
else
src.name = user_name
usr.icon = 'M-norm.dmi'
usr.icon_state = "Normal"
world<<"<font size = 1><font color = green><B>Event: <font color = black>[usr.name] the almighty has logged in</font>"
usr.Save()


Problem description:
When I create a new character it uses the
world<<"<font size = 1><font color = green><B>Event: <font color = black>[usr.name] the almighty has logged in</font>"
4 times and I only need it to be used once.

is your name four characters long, if it is, its because of the

for(var/N in un_wanted_names && html)


not sure exactly how to fix this but that may be your problem
In response to KirbyAllStar
No I just made a char name with one longer than 4 letters and it still did it. Here is the code for the line you though had the problem.
var/list/html = list("<",">","font","size")


var
list
un_wanted_names = list("") //my key is there just for a test

name_length
maximum_name_length_amount = 15
In response to CYN
hmmm that interesting, how many keys are in the un_wanted_names thats the only thing I can think of that would loop it like that
In response to KirbyAllStar
No keys I just used words I don't want like swear words <.<
In response to CYN
how many words are in the list?

for(user_name in un_wanted_names && html)


maybe that would help but I'm not sure
In response to KirbyAllStar
1 right now
In response to CYN
I can't figure it out maybe a more experienced programmer will come a long and figure it out.

Sorry I couldn't help
In response to KirbyAllStar
don't worry bout it. Thanks for trying though.
The problem is that you're "logging in" message is inside of a loop. This makes it display the logging in message as many time as your name doesn't have any un_wanted_names. In order to fix it, you will have to take it out of the for loop, and make sure that part of the code only gets executed when all conditions are met.

Another problem is that you're using goto when you can easily use a while loop to keep on looping until your name is valid. You can combine your name checking conditions into one proc to simplify your loop.

proc/isValidName(name)
if(!name) // return 0 when the conditions do not meet
return 0
if(length(name) > 20)
src << "Name is too long"
return 0
for(var/i in un_wanted_names + html)
if(findtext(name, i))
src << "Please do not put HTML in your name"
return 0
return 1 // return true if all the conditions passed

// in newchar2()

var/user_name = ""
do
user_name = input(src, "Your name?", "Name") as null|text
while(isValidName(user_name))
// let the user input their name at least once. If the
// user_name is invalid, then it will keep letting the
// player input a name

src.name = user_name
world << "[src.name] the almighty has logged in"
src.Save()
In response to KirbyAllStar
I suggest instead of using && use || its this \ and shift.
~Grand~
In response to KillerGrand
the && makes sure all requirements are met while || will run the code if one requirement is met I believe.
In response to Unknown Person
Now when I try that code, I get this error. Login.dm:132:error::invalid expression; on the marked line
    newchar2()
var/user_name = ""
do
user_name = input(usr, "Your name?", "Name") as null|text
while(isValidName(user_name))
src.name = user_name //RIGHT HERE
world<<"<font size = 1><font color = green><B>Event: <font color = black>[usr.name] the almighty has logged in</font>"
usr.Save()

In response to CYN
I think its because

src.name = user_name //RIGHT HERE
world<<"<font size = 1><font color = green><B>Event: <font color = black>[usr.name] the almighty has logged in</font>"
usr.Save()


isn't actually inside the while, only the user_name = input(...

this is because its a do while, so I don't think the stuff under the while should be indented

I know thats how it works in C++ is it the same for DM?
In response to KirbyAllStar
no. then it executes the code even if the while isn't true.