ID:266295
 
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?
mob/verb/Say(T as text)
if(length(T)>=50)
usr<<"Too long!"
else
world<<"[usr]: [html_encode(T)]")



That's it.
Does anyone know how?

lentext()
length()
In response to Nadrew
Nadrew wrote:
> mob/verb/Say(T as text)
> if(length(T)>=50)
> usr<<"Too long!"
> else
> world<<"[usr]: [html_encode(T)]")
>

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
In response to LordJR
Do what I did 3 strikes and Boot().
In response to LordJR
Well, I'm not doing it for spam protection. I need people to choose short names in my game or things get screwed up.
In response to Lord of Water
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
In response to 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. =)
In response to Spuzzum
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,
In response to 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:
  1. It is > 3 and < 13 chars long
  2. It is different then the player's key
  3. It is different from the names of others in the game
In response to Lord of Water
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.
In response to Spuzzum
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.