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
Ashur
Novice


Joined: 25 Jul 2011
Posts: 39

PostPosted: Sun Sep 15, 2013 8:10 pm   

Simple Regex
 
I'm trying to write a trigger that will highlight my health values in special colors depending on the value.

The string I need to match is : You are physically <feeling very well> and mentally <in full vigour>. (<> denotes the values that change, they are not present in the actual string)

In the this case, I'd like 'physically feeling very well' to be a nice happy green and 'mentally in full vigour' to be a nice happy blue. I'll have to do it in two triggers, and that's fine. The trigger I have for the first part looks like this, so far:

#TRIGGER {physically (*)} {#IF %match(%1, "feeling very well") { #CW GREEN }} }

That works great, except it colors the whole line after 'physically'. Is it possible to change the trigger to match everything between 'physically' and 'and' but not color 'and'?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Sep 16, 2013 12:09 am   
 
1)learn zscript. Regex is only necessary if you plan on doing coding of any sort outside of CMud. Most of the feature functionality in CMud is tied into Zscript, so it's best to learn about third-party stuff like regex and lua after you are familiar with the features. Not everything available to Zscript is available and/or properly working when accessed via these third-party features.

2)you only need one trigger for this.

3)#CW applies to everything in the trigger pattern, from start to finish. It does not apply to any portion of the line that appears before the pattern, nor any part that appears after (though in your case, the pattern happens to match to the very end). With this in mind, #PCOL may be a more appropriate command to use. #PCOL and #PSUB have some quirks to watch out for, however, such as the fact that #PSUB only counts character positions based on the original line matched rather than on the up-to-now processed version (this means that %x2...%x99 will no longer be accurate should %x1 be changed to a different-length string).

4)check out the patternmatching helpfile. Plain, literal text will stop wildcards, so the easiest fix to your pattern would simply be to include the " and" or " and mentally" part of the line.
_________________
EDIT: I didn't like my old signature
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