ID:272691
 
I'm sure everyone knows how the DM language adds the word "The" in front of any defined name variable text if the first letter isn't a capital letter.

Is there a way to override that built in DM thing? If not, how would I make my "create name" input() proc to check the first letter of the name they type in, if it's a capital or not?
The \proper or \improper text macro:

mob/verb
create()
var/choice = input("Create what?", "Create") as text
alert("You chose to create \improper[choice].")
Look up copytext() and text2ascii().
mob/verb/name_change()
var/t = input(src,"text","text",key) as null|text
if(!T) return
if(text2ascii(copytext(t,1,2)) in 65 to 90)
src << "You need to capitalize your name"
return
name = t


copytext() copies the letters between its 2nd and 3rd arg. Note that the number in the third arg is like a stopping point, it isn't included in the text, but the second arg is included in the text. text2ascii() converts text to an ASCII value, and the capital letters in ASCII happen to be between 65 and 90.
In response to Jeff8500 (#2)
Or you can just capitalize it using uppertext() o_O
In response to Andre-g1 (#3)
But what if they try naming themselves an improper noun, and they realize they can't do that? :P. I thought about that, but he asked how to check, not how to change.
In response to Xooxer (#1)
The \improper text macro adds "the" in front of the name regardless if it's capitalized or not.
In response to Mizukouken Ketsu (#5)
So I'll use \proper >_> rofl
In response to Jeff8500 (#2)
Well, that code certainly doesn't compile for me.

if(!T) return -> variables are case sensitive sir.
if(text2ascii(copytext(t,1,2)) in 65 to 90) -> An interesting through, but my compiler says: error::invalid expression

Also there's a logic error, you never placed in ! operator in that if statement. So if it had worked, it would have asked people for a capital letter regardless if they had one.

Also, your ASCII values are a little off.
A -> 65
Z -> 90
a -> 97
z -> 122

But following your idea:
mob
verb
name_change()
var/t = input(src, "please set your name", "name", key) as null|text
if(t)
var/first_letter = text2ascii(copytext(t, 1, 2))
if(first_letter >= 97 && first_letter <= 122)
alert(src, "You must have a capital letter", "Error")
return
else src.name = t


But there are infinite better ways to handle this.
In response to Tiberath (#7)
Woops, those were some stupid mistakes!

if(text2ascii(copytext(t,1,2)) in 65 to 90) -> An interesting through, but my compiler says: error::invalid expression

I heard that would work as short hand outside of switch, looks like I either remembered incorrectly, etc.

if(!T) return -> variables are case sensitive sir.

I should have just made it T, I usually name my one letter variables capital letters, so I make that mistake occasionally.

Also, on the ASCII thing, I meant to put a ! in that if(), too! Though you're right, it would create slightly less overhead if you check if it's between 97 and 122.
In situations when you want to ensure the name displays literally, you can simply embed the name variable instead of the actual object reference. For instance:
mob
old_man
var/message
verb/Talk()
set src in view()
usr << "[src] says: [src.message]"
// The old man says: ...
verb/Pulverize()
src << "Who do you want to pulverize?"
for(var/mob/M in view(src))
src << "<a href='?src=\ref[src];cmd=del;target=\ref[M]'> \
[M.name]</a>\..." //output: "Kaioken, old man, whoever_else_is_there"
//only topic link included.
//Topic() override comes in separate packaging.

Code intended for demonstration only. I am not liable for any consequences or side effects from use. Pulverizing of old men unrecommended.
In response to Jeff8500 (#8)
Relax, we all have our bad days. =)

There have been occasions where I've seen syntax's for if() statements and the like that I didn't know were possible. I generally forget about them as well.
In response to Tiberath (#10)
Same here; and actually, the syntax he used exists! :P
It's probably confused by proc(s) for one reason or another. =\ Dunno if it's worthwhile to report.
This works, AFAIK:
var/MyNum = rand(1,100) //or text2ascii()...
if(MyNum in 10 to 20)
//...
In response to Kaioken (#11)
These all compile and run fine for me:

        var/i=rand(1,10)
if(i in 3 to 6) usr<<"a"
if(rand(1,10) in 3 to 6) usr<<"b"
var/t="Test"
if(text2ascii(copytext(t,1,2)) in 65 to 90) usr<<"c"


I'm not sure what was causing Tiberath's error.