Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
FuSoYa
Novice


Joined: 10 Feb 2007
Posts: 34
Location: Denton, TX

PostPosted: Sun Apr 20, 2008 4:31 am   

Coloring random variables.
 
If there is something I want to be captured and colored such as [NES Quit]

How do I make it color ONLY the items within the brackets and not the brackets?

Thanks.

Brandon
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sun Apr 20, 2008 12:08 pm   
 
You need to use #pcol and set up a back reference in your pattern (i.e. use parentheses) and then use %x1 (or whatever number suits your backreference) to tell it where to colour. Remember that square brackets are usually special characters, so you'll need to escape them, too.. something like this:

~[(NES Quit)~]
#pcol green %x1
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Apr 20, 2008 12:18 pm   
 
There're a number of methods, mostly dependent on how confident you are with regexes. The simplest way would probably be to use #sub and MXP:

#trig {~[(*)~]} {#sub {%concat("[<color whatevercolournameiwanttouse>",%1,"</color>]")}

A more complex way would be to use positive lookbehind and lookahead in a regex so that the brackets must be there, but don't form part of the match. If you don't know what I'm talking about, it's probably past your abilities. If you're looking to learn, try this site, which'll teach you all about regex syntax. Lookahead and lookbehind will likely be in the advanced section.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
FuSoYa
Novice


Joined: 10 Feb 2007
Posts: 34
Location: Denton, TX

PostPosted: Sun Apr 20, 2008 2:31 pm   
 
#trig {~[(*)~]} {#sub {%concat("[<color white>",%1,"</color>]")}

When I tried this one it told me error parsing command illegal token? What did I do wrong?
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun Apr 20, 2008 2:35 pm   
 
You're missing a closing brace
it should be
Code:
#trig {~[(*)~]} {#sub {%concat("<color white>",%1,"</color>")} }
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
FuSoYa
Novice


Joined: 10 Feb 2007
Posts: 34
Location: Denton, TX

PostPosted: Mon Apr 21, 2008 5:22 am   
 
Ok I got it to work but now how do I get it to keep the brackets that are already there in the same dull green color?

Brandon
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Apr 21, 2008 5:41 am   
 
Put them at the ends of the string, outside the colour tag:

#trig {~[(*)~]} {#sub {%concat("[<color white>",%1,"</color>]")} }

You can always put colour tags around each of them to colour them properly if that removes the colours, too.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Apr 21, 2008 5:42 am   
 
The one Dharkael posted forgot to put in the [ ] in the #sub.

Should be:

Code:
#sub {%concat("[<color white>",%1,"</color>]")}
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Mon Apr 21, 2008 11:27 am   
 
Can someone explain why you would prefer sub to pcol (assuming that really all you want to do is colour and capture)? Sorry if I'm being dense, it just seems like extra work.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Apr 21, 2008 12:29 pm   
 
PCOL keeps colour codes, SUB removes them. You can just put whem into the string you sub, though, so it's not that big a deal.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Mon Apr 21, 2008 1:46 pm   
 
OK, so if you wanted to make the brackets a different colour, too, you would need sub, but why use it in this case (instead of pcol)? Still confused here.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Apr 21, 2008 3:06 pm   
 
Okay, I was confused - when I said PCOL in the post above, I meant PSUB. You could use PCOL here, actually, and it should work fine.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net