Monday, April 25, 2005

 

String capitalisation in Lima Mudlib

Something that was annoying both myself and my friend helping on Kelianon was that says and tells were not automatically capitalising the first letter of the sentance.

So I begin to trawl through the files to see what I can find. Most of the grammar functions on strings appear to be held in the module file m_grammar.c (/std/modules/). Looking through this found me some usefull functions such as punctuate(str) which automatically appends a period to the end of the sentance if no other punctuation is detected.

No capitalisation function was found, however on checking the module m_messages.c I noticed a call within another fuction to capitalize(str). I'm not exactly sure where this function is kept as yet, however armed with this knowledge I was able to take a look at the say and tell commands.

Firstly I looked in the verbs folder (/cmds/verbs/)and modified the file in there. I'll not go into great detail about the success of this, as some time was spent playing with the say verb, only to find that it's being overridden by the file of the same name in the players commands folder (/cmds/players).

Checking out say.c first, I found this to be easily modified with only a single line needing changed to:

msgs=this_body()->action(({this_body()}),
"%^SAY%^$N $vsay:%^RESET%^ $O",
punctuate(str));
Note the capital $O to capitalise the string. It's also worth noticing that say is automatically punctuated with period at the end of the string as well.

The tell.c file was slightly harder as, although you would expect it to be coded in a similar manner, the way in which tell works is slightly different. The following code was adjusted to:

mystring = sprintf("%%^TELL%%^You tell %s:%%^RESET%%^ %s\n",
who == this_user() ? "yourself" :
capitalize(who->query_userid()),
capitalize(arg));
deststring = "%^TELL%^" + capitalize(this_user()->query_userid()) +
" tells you: %^RESET%^" + capitalize(arg) + "\n";

Here I needed to add the function captialize(str) which I had found earlier to take the variable arg, for both mystring and deststring, which are then sent to the player and the destination player respectively.

Files updated and now we have automatic capitalisation of the first letter of the sentaces created when using the say and tell commands.

Labels: , ,


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?