Title: "Acronym Replacement"
Author: Martyr2
Updated: March 21, 2001
Written for [#clan-x-scripterz] 
Definition: - Acronym Replacing means the act of taking shorthand, such as lol or brb, and replacing it with the full extended version like Laugh Out Loud and Be Right Back respectively.

Most acro replacers now a days are scripted using the identifier $replace. While this does work to some of a degree, you will often find it triggering a replace when you type a normal word that consists of the same letters... like lolly pop would end up being Laugh Out Loudly pop.

So lets attack the problem from a different angle, shall we? We know that when we type "lol" it is often its on separate word; Most of the time the only word for a given line you type. For instance you may type...

<Martyr2> lol or <Martyr2> Thats too funny! lol

Sooooo lets treat lol and the others as its own word and hence its own token in a sentence. If you are unfamiliar with using tokens, you can read our article titled "Can't Pass without a token" where I take you through the steps of learning the magical mIRC scripting token in detail. For a quick explanation, Tokens are any piece of info that is separated by some other special character. In a sentence, each word is separated by a space right? Well in our new replacer, we will treat what we type just that way. Simple words divided by the space character (Also known as $chr(32) or ASCII value number 32).

You will notice in the mIRC help file under tokens that there is an identifier known as $reptok... or Replace Token. What we will do is use our acro replacer to catch the sentence we type, find where the lol token is and replace that token with its extended version. Sounds complicated? Its not too bad. Lets show it below and then run through step by step.

on *:INPUT:*:{ 
  if (/* !iswm $1) { 
    var %replace.acro = $1-
    if ($istok(%replace.acro,lol,32)) { %replace.acro = $reptok($1-,lol,laugh out loud,32) | goto restart } 
    msg $active %replace.acro | halt
The first line shows a basic "on INPUT" event. If you don't know about the on input event, I suggest you look in the help file. The code reads that for anything we type in any window we do the following...

Line2: Check to see if the first word is a command.
Line3: If its not, set a variable (%replace.acro) to what we typed.

Line4: Goto tag for our loop.

Line5: If "lol" is in the sentence, replace that token with laugh out loud, using character 32 (Our space) as the separater. Then go back to the start of the loop.

Line6: Message the window what we typed, having replaced the token. Halt the rest. If you do not halt the event on line five, what happens is that it will message the channel or window double. It does this because one, it will send out text on as normal and second, it will then send our editted version also. Giving you this type of effect...

<Martyr2> Funny! lol <Martyr2> Funny! Laught Out Loud

One more small warning about this... On Input, like most events, are very stubborn when it comes to putting them with other events of the same type. Meaning, if at all possible, try to avoid using two on input events in the same script. If you really want to have both, try to combine them into one or place the second on input into a new fresh remote file. (For newbies, go into remote select file from the menu, and click new)

Adding more to this

Ok, so you want to add a brb and possibly roflmao acro to it. No problem, for each additional acro, simple add another line. Below is the same code as above, but you will see two lines (Marked in red) which I have added. Notice they are very similiar to the other if statement.

on *:INPUT:*:{ 
  if (/* !iswm $1) { 
    var %replace.acro = $1-
    if ($istok(%replace.acro,lol,32)) { %replace.acro = $reptok(%replace.acro,lol,laugh out loud,32) | goto restart } 
    if ($istok(%replace.acro,brb,32)) { %replace.acro = $reptok(%replace.acro,brb,be right back,32) | goto restart }
    if ($istok(%replace.acro,roflmao,32)) { %replace.acro = $reptok(%replace.acro,roflmao,rolling on the floor laughing my ass off,32) | goto restart }
    echo -a %replace.acro | halt
What is great about doing it like shown above is that when you type it all in one sentence, they are all replaced. For instance if you were to type the following....

<Martyr2> Oh man thats funny! lol oops brb

It would result in this...

<Martyr2> Oh man thats funny! Laugh Out Loud oops Be Right Back


Acronym Replacers take a small abbreviated word or sentence and replaces it with the full version instead. They are often done with $replace and you will see others mention that, but it has limitations. $Reptok will replace "Tokens", which are pieces of info separated by special characters, with the full version token instead. This prevents words which contain letter sequences with lol and brb in them from triggering. And it replaces it only if they are their own word or isolated token.

For more information:

Please read the Clan-X-Scripterz Article titled "Can't Pass without a token" which is also written by yours truly. It will clear up most questions about the understanding and use of tokens and the $reptok Identifier.

.::(Martyr2)::. © 2001 Clan-X-Scripterz