ID:1221682
 
(See the best response by Kaiochao.)
Well, I know I've done this before so it is possible actually. But I can't remember how I did it. Can anyone enlighten me? I want to make it so that when:

src.name = input("What would you like your name to be?", "Name") as text


is longer than 20 (But not equal to)

that it just automatically shortens it.

I tried:

if(src.length(src.name)>20) //This line is correct so far
length(src.name) = 20 //Obviously this is wrong but I feel that I am close. q_q
Bump
Best response
You're gonna want to use copytext(). It returns a section of text between two positions. In your case, you'd want the text from the beginning (1) to a certain point (20 + 1; the +1 will include the 20th character).
src.name = copytext(src.name,1,21)?

Like that?

Also, I call:

src.name = input("What would you like your name to be?", "Name") as text
if(src.length(src.name)>20)
length(src.name) = 20

At login. It does absolutely nothing. But, if I put it in a verb it will call it when I click the verb. What's up with that? Am I forgetting something simple or what?
Why would you do that? I mean, just warn the user, return, and input the text again. Some players would be annoyed at that.
It will, Eternal. I did this same thing with my OOC but differently. If you pass the 250 character limit it throws the message back at you instead of the world without character limits. You can copy and paste it in bursts(cut it in half and paste 2 messages). This way you don't lose those long messages.
In response to Eternal_Memories
Eternal_Memories wrote:
Why would you do that? I mean, just warn the user, return, and input the text again. Some players would be annoyed at that.

Programming-wise, I answered his question, but I completely agree with this design choice.
mob/Player/proc
Rename(T as text)
if(length(T)>20)
src.name = copytext(src.name,1,21)
switch(input("Would you like your name to be [src.name]?")in list("Yes","No"))
if("Yes")
return
if("No")
src.Rename()
else
src.name = T
switch(input("Would you like your name to be [src.name]?")in list("Yes","No"))
if("Yes")
return
if("No")
src.Rename()


Gaiys, gaiys.. I got deez.. I did it long ago. Lol. I know people hate that. :P
I'm dumbfounded as to when I call src.Rename() in the mob/Player/Login() area as to why it's the ONLY procedure that does not get called. It's probably getting called but not prompting me to input text... :/
You're not actually telling it to prompt you for text as far as I can see, but you haven't shown how you are calling the proc. As you're using a proc and not a verb Rename(T as text) will not give you a prompt.

mob/Player/Login()
..()
Rename()

mob/Player/proc
Rename()
src.name = input("Enter your name.") as text
src.name = copytext(src.name,1,21)
switch(input("Would you like your name to be [src.name]?")in list("Yes","No"))
if("Yes") return
if("No") src.Rename()
mob/Player/proc
Rename()
var/T = input("What would you like your name to be?") as text
if(length(T)>20)
src.name = copytext(src.name,1,21)
switch(input("Would you like your name to be [src.name]?")in list("Yes","No"))
if("Yes")
return
if("No")
src.Rename()
else
src.name = T
switch(input("Would you like your name to be [src.name]?")in list("Yes","No"))
if("Yes")
return
if("No")
src.Rename()

In your opinion, should this work? -- And T as text was there before when it was a verb.
Almost, as you are using var/T as the variable to hold the name, you will have to change this:

src.name = copytext(src.name,1,21)
//All this is doing is reducing src.name to 20 letters, disregarding the input (var/T)

src.name = copytext(T,1,21)
//This will set src.name to the first 20 letters or less of var/T. This is what you want


My previous example did just this, only I shortened it.
Remember to include if(!T) src.Rename(), or it'll be blank if they don't type anything o-o
Thanks, Eternal. I had a feeling I'd run in to that problem in about a day or so. xD I always forget the small stuff. -- Danny, wouldn't saying "src.name = copytext(src.name,1,21) when there is actually LESS than 20 characters cause an error because it's out of bounds? Or does that not happen here. >.> Just curious.
Okayy.. I got it to work.. but awkwardly.. Some part in my login code.. cuts off everything after it.. What the hell?
So, I traced my code and it seems that if I put it before this switch statement it runs fine. No matter where I put it even. But if I put it after it it will not run a single thing. In fact, no code will. Why? I tested to see if it was any codes within the switch statement.. Nothing. It's the switch statement itself.

     switch(alert("Welcome to the first session of \"Legend of Another World\"!","Welcome","Continue","Skip"))
if("Continue")
switch(alert("This is the alternative version so don't be disappointed.","Welcome","Continue","Skip"))
if("Continue")
switch(alert("The best part has yet to come. We just want to get a few feedback from people is all.","Welcome","Continue","Skip"))
if("Continue")
alert("Why don't you click the commands tab and start a vote? Suggest a new update and have the server vote on it.")
return
if("Skip")
return
if("Skip")
return
if("Skip")
return
src.Rename()
I assume all this code is under mob/Player/Login()? The reason this will not work is because you are using return everywhere. return stops the execution of the current proc, and as you are calling it no matter what the player clicks, the proc is stopped before src.Rename() can be called. The two examples below should help you understand.

In this example, Players would have the same problem you're having, Rename() is never called:
mob/Player/Login()
..()
switch(alert("Choose wisely",,"Blue Pill","Red Pill"))
if("Blue Pill")
world << "You wake up at home."
return //Process ends here
if("Red Pill")
world << "You tumble down the rabbit hole."
return //Process ends here

Rename() //This is never called.


In this one, Rename() will be called, but only if the player clicks on the "Red Pill" button:
mob/Player/Login()
..()
switch(alert("Choose wisely",,"Blue Pill","Red Pill"))
if("Blue Pill")
world << "You wake up at home."
return //Process ends here
if("Red Pill")
world << "You tumble down the rabbit hole."
//No return proc here, so it continues to
//execute the code below this line.

Rename() //This is called when they
//choose the Red Pill.
I know what return does. Actually. When I still had this code i my game I removed return from the first "Skip" and tried it. Nothing. So I just presumed something was buggy. But all is well now. Problem resolved.