How do I determine the length of a text string?
var/textstring
if(textlength(textstring) > 20) src << "It's too long!"
I want to do somthing like that...
Does anyone know how?
ID:266295
![]() Nov 15 2001, 4:28 pm
|
|
Nadrew wrote:
> mob/verb/Say(T as text) That's it.Also you mentioned about putting a timer on the amount of post a person can make to protect against spamming. How would the code look for something like that? I got length set and working fine. LJR |
Well, I'm not doing it for spam protection. I need people to choose short names in my game or things get screwed up.
|
Lord of Water wrote:
Well, I'm not doing it for spam protection. I need people to choose short names in my game or things get screwed up. You can directly cut off their name with copytext(), or you can use lentext() and length() to check how long a text string is(Note that lentext() takes less time because it goes through less checks as far as I remember). Alathon |
You can directly cut off their name with copytext(), or you can use lentext() and length() to check how long a text string is(Note that lentext() takes less time because it goes through less checks as far as I remember). Not sure, actually... that was a random guess. However, in my educated opinion: Strings in BYOND are likely handled as char arrays. Thus, lentext() can query the size of the array and that's that -- done in a flash. However, length() might search through the entire string until it finds a \0 character -- this allows it to work for files and all other mediums as well. In any case, the difference is probably negligible (i.e. on the order of a few picoseconds or so). Dantom might shed light on the situation as to how incorrect my views are. =) |
Spuzzum wrote:
In any case, the difference is probably negligible (i.e. on the order of a few picoseconds or so). Dantom might shed light on the situation as to how incorrect my views are. =) Ah, well, one less picosecond of lag is a picosecond closer to the lagless game we all dream of. Alathon, |
Hehe. Any way, I don't want to cut their name off. In my new text engine, names have three requirements.
A name is valid if:
|
It is different then the player's key The others are valid... but that might be a problem. If I made a key called 'Alayus Proudmoon', then logged into a game using it, why couldn't I use 'Alayus' as my character's first name? Of course, that's the exception. You could do what Lexy does -- take a name = ckey(name) of whatever they enter, which strips punctuation from it. Perhaps some general name-stripping features would be useful. |
The others are valid... but that might be a problem. If I made a key called 'Alayus Proudmoon', then logged into a game using it, why couldn't I use 'Alayus' as my character's first name? Alayus would be accepted as your character's name. However, Alayus Proudmoon would not be accepted because it is too long and is the same as your key. |
That's it.