![](templates/Classic/images/spacer.gif) |
dskorren Novice
Joined: 07 Feb 2002 Posts: 48 Location: Philippines
|
Posted: Tue Nov 30, 2004 1:53 am
help on a color alias |
I've read Imri's post regarding the capitalization and coloring
of words you enter on an alias and learned for myself how fast
regexp can be compared to using zscript for string manipulation.
What i'd like to do is to re-color what I type:
lowercase -> %ansi(cyan)
uppercase -> %ansi(high,cyan)
numbers -> %ansi(high,red)
all others -> %ansi(high,yellow)
I only gotten to coloring uppercase but im at a loss on how to
proceed to color the rest of the string.
Any help would be greatly appreciated. |
|
|
![](templates/Classic/images/spacer.gif) |
Danlo Magician
![](images/avatars/1578549964100daf016b9b.jpg)
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Thu Dec 02, 2004 4:30 am |
This will do the job for you:
#fun ColorString {%subregex( "%1", "(.{1})", "%if(%isnumber("%%1"), %insert(%ansi(high,red), "%%1", 1), %if(%pos(%%1, "~!@$%~#^&~*:~;?"), %ansi(high,yellow)%%1 , %if(%upper(%copy("%%1",1,1)) == %copy("%%1",1,1), %insert(%ansi(high,cyan),"%%1",1), %insert(%ansi(cyan),"%%1",1)))")}
To use: @colorstring(String to be Colored) |
|
|
![](templates/Classic/images/spacer.gif) |
dskorren Novice
Joined: 07 Feb 2002 Posts: 48 Location: Philippines
|
Posted: Thu Dec 02, 2004 7:37 am |
Thank you for your code Danlo. Its quite a mouthful and I think it will take me a long time to find out how that one works. It is light years away from what I came up. *high five*
|
|
|
![](templates/Classic/images/spacer.gif) |
Danlo Magician
![](images/avatars/1578549964100daf016b9b.jpg)
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Thu Dec 02, 2004 11:32 am |
The way it works:
It creates a player-defined function named ColorString, which executes a subregex function, which loops through the inputted string character by character. It then detects what the character is, and colors it accordingly.
First, it checks if the character is a number, then it checks if it is a non-alpha character, and then it checks if it is uppercase or lowercase.
This will only color it on your screen, of course. If you want it to color it on the mud, you'll have to insert the colorcodes used by your mud, rather than using %ansi() function. |
|
|
![](templates/Classic/images/spacer.gif) |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|