ID:171708
 
How would I "prevent" someone from inputting too many characters into a text input screen?

Im not talking about returning zero AFTER they input too many characters and have to go back and retype their text all over again.

Example:

Bob wants to type a message. He clicks the say verb and types his text. Oops! Bob can't type his full message because the coding doesn't allow him to type more than 10 characters a message. So his message comes out: Can anyone h...
use copytext.

mob/verb/Say(T as text)
world<<"[src]: [copytext(T,1,10)]"

However, they can still type more than 10 characters. I don't think you can stop that.
In response to Airjoe
Airjoe wrote:
use copytext.

mob/verb/Say(T as text)
world<<"[src]: [copytext(T,1,10)]"

However, they can still type more than 10 characters. I don't think you can stop that.

In a browser interface you could of course put a limit on a text edit field in a form, but that doesn't guarantee they won't manually screw with the URL.

Lummox JR
In response to Airjoe
to add a "..." at the end of their text if they over type would I put "If copytext returns true, text string +- "...""?
In response to Lummox JR
how could they "screw" with the url and affect the number of characters allowed?
In response to ZLegend
Juat add ... at the end of the usr << ""
In response to Dession
Excuse my french but you obviously didn't not read my thread fully. I only want a "..." at the end of the text string if the text string exceeds so many characters.
In response to Airjoe
This is what I have so far but its no good...

mob/verb/Say(T as text)
if(lentext(T)<=10)
T+="..."
world<<"[usr]: [copytext(T,1,10)]"
In response to ZLegend
I've got a question .... how do you make turn-based fighting systems?
In response to DragonMasterGod
Please post your own thread. I know your probaly new so I will explain. Go to either the bottom or the top of the forums web page and click "Post". You'll know what to do from there.
In response to ZLegend
It really isnt that hard lookup If() and copytext in the reference.
In response to ZLegend
ZLegend wrote:
how could they "screw" with the url and affect the number of characters allowed?

They could create their own byond://? link and type it in to Dream Seeker.

byond://?action=say&text=This is more than 10 letters!


Never completely trust the client to validate stuff. Always have some code on the server that checks the same thing.
In response to ZLegend
ZLegend wrote:
Excuse my french but you obviously didn't not read my thread fully. I only want a "..." at the end of the text string if the text string exceeds so many characters.

You should read what he posted then. It's in english. =)

what you are doing in your code is adding ... to the end of the string then chopping it down to 10 chars. Example. if Bob typed "this is more than 10 chars" what you code would do is add "..." to the end of that string making it "this is more than 10 chars..." then your code cuts it down to 10 chars making the out put "this is mo"

instead you should do this:

verb/say(T as text)
if(T.len >= 10)
T = copytext(T,1,10)
usr << "[T]..."
else
usr << "[T]"


In response to Dession
Ya it isnt hard to look for it. but finding it is the hard part which i couldn't do.
In response to Jik
T.len is an undefined variable... ='( I hate these.

fixed it
mob/verb/say(T as text)
if(lentext(T) >= 10)
T = copytext(T,1,10)
usr << "[T]..."
else
usr << "[T]"


thanks a lot
In response to ZLegend
mob/verb/Say(T as text)
if(length(T)>10)
T=copytext(T,1,11)+"..."
world<<"[usr]: [T]"


You had a < instead of >

Also, I used length() instead of lentext(). As far as I know, it shouldn't make a difference.