big_luke Newbie
Joined: 11 Jun 2005 Posts: 9
|
Posted: Tue Jun 14, 2005 2:29 am
"Say" modification |
I initially wrote this script several months ago, before the new spellchecker function, to allow me to not make an idiot out of myself when talking on my muds. Sometimes, when using SAY TO <whoever>, I would mispell their name, and instead of a properly targetted say to them, I would have an embarassing mispell of their name in a regular say.
This script screens the say, and replaces the target of the say to with the correct spelling if it is mispelled. It works over the regular say, so it works in the background for the user.
You can add "Corrections" with the syntax ADDSPELL <wrong spelling> <right spelling>. You can remove them afterwards with RMSPELL <wrong spelling>.
You can also view a neatly formatted list of the corrections using SHOWLIST. As you can see, the vast bulk of the code that went into this correction is a result of this alias but I think it looks neat so its worth it.
Here is the code, as should be typed in the command line (though if you DO copy and paste it I recommend into wordpad first, to remove any webpage-related formatting of the text):
Code: |
#function longestmemberinternal {%if( %1<%numitems( @%2), @longestmemberinternal(%eval(%1+1),%2,%max(%3,%len(%item(@%2,%1)))), %max( %3, %len( %item( @%2, %1))))}
#function longestmember {%if( %numitems( @%1)>1, @longestmemberinternal(1,%1,0), %len( %item( @%1)))}
#function generatedelimiterline {%cr+@generatedelimiterlinespacesleft(0,"")+@generatedelimiterlinespacesright(0,"")+}
#function generatedelimiterlinespacesleft {%if( %1<@leftsidewidth, @generatedelimiterlinespacesleft(%eval(%1+1),%concat("-",%2)), %2)}
#function generatedelimiterlinespacesright {%if( %1<@rightsidewidth, @generatedelimiterlinespacesright(%eval(%1+1),%concat("-",%2)), %2)}
#function generatedelimitedtext {%cr|@generatedelimitedspacesleft(0,"",%1)%ansi( 12)%1 %ansi( 11)| %ansi( 10)%2%ansi( 11)@generatedelimitedspacesright(0,"",%2)|}
#function generatedelimitedspacesleft {%if( %1<%eval( @leftsidewidth-%len( %3)-1), @generatedelimitedspacesleft(%eval(%1+1),%concat(".",%2),%3), %2)}
#function generatedelimitedspacesright {%if( %1<%eval( @rightsidewidth-%len( %3)-1), @generatedelimitedspacesright(%eval(%1+1),%concat(".",%2),%3), %2)}
#var rightspelllist {Zugg}
#var wrongspelllist {Zuug}
#alias showlist {leftsidewidth=%max( %eval( %len( Wrong)+2), %eval( @longestmember(wrongspelllist)+2));rightsidewidth=%max( %eval( %len( Right)+2), %eval( @longestmember(rightspelllist)+2));#echoprompt {@generatedelimiterline @generatedelimitedtext(Wrong,Right) @generatedelimiterline};#loop 1,%numitems( @wrongspelllist) {#echoprompt {@generatedelimitedtext(%item(@wrongspelllist,%i),%item(@rightspelllist,%i))}};#echoprompt {@generatedelimiterline}}
#alias rmspell {#if (%ismember( %1, @wrongspelllist)) {rightspelllist=%delnitem( @rightspelllist, %ismember( %1, @wrongspelllist));wrongspelllist=%delitem( %1, @wrongspelllist);#ech {Deleted Entry %1 from Wrong Spell List}} {#echo No such word found - or, incorrect syntax. RMSPELL ~<mispelling~>}}
#alias addspell {#if (%ismember( %1, @wrongspelllist)) {#echo {This particular word already has a value. If you wish to change it, use RMSPELL ~<item~>.}} {#if (%2) {wrongspelllist=%additem( %1, @wrongspelllist);rightspelllist=%additem( %2, @rightspelllist)} {#echo {Incorrect Syntax: The correct usage is ADDSPELL ~<mispelling~> ~<correct spelling~>}}}}
#alias say {#if (%pos( to, %0)=1) {#if (%ismember( %2, @wrongspelllist)) {~say to %item( @rightspelllist, %ismember( %2, @wrongspelllist)) %copy( "%0", %pos( %3, "%0"), (%len( "%0") - %pos( %3, "%0") + 1))} {~say "%0"}} {~say "%0"}} |
This also includes my previous longestmember function.
If you run into any problems, let me know.
Enjoy. |
|