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


Joined: 18 Dec 2006
Posts: 47

PostPosted: Sat Feb 17, 2007 9:20 am   

Regex Trigger Question
 
I have a trigger that had been working most of the time, but had been a little flaky, so I decided to tweak it...

Now, it _almost_ works like it's supposed to, but at least it's consistant... which should help me get it fixed. I messed around with it a little, but I'm to the point I'm not really sure what the problem is, and know very little about Regex and how it's handled in cMUD.

The trigger is one from a City Enemy script Larkin posted for Achaea, and the pattern is:

\b((?:@CityEnemies))\b

The value is:
#IF (%ismember(%lower(%1),@TheInfamous)) {#cw gold,firebrick} {#cw antiquewhite,firebrick}

So, essentially, I want to color all city enemies in one color, but if they are in both @CityEnemies and @TheInfamous lists, to color them a different color.

Currenty, this works fine if there is only one name in a line that belongs to either of these lists, if there are two names in one line, they both get colored whatever the first one should be.

For example if
@CityEnemies = Tom, Dick
@TheInfamous = Tom

If I do: #SHOW Tom, Dick - Both are colored in gold (as Infamous), but I would expect the first in gold, second in white.

If I do #SHOW Dick, Tom - Both are colored in white (As only City Enemies), but I would expect the first in white, second in gold.

Hopefully that's enough information to make my issue clear, but if not, let me know, and I'd be happy to provide more.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sun Feb 18, 2007 2:25 pm   
 
It appears that you have found an inconsistency in the behavior in zMUD versus the behavior in CMUD. In zMUD, the pattern would fire twice and color each name correctly. In CMUD, the pattern fires only once per line and colors all matches. If you switch the #CW to #PCOL (adding %x1 after the color names), you get one name colored, but the other one does not change color.

Also, you can remove the inner set of parentheses in your pattern. (?:@CityEnemies) means to match on the variable but not to capture to %1. (@CityEnemies) will match and capture, which is what you want here.

If your string list contains Tom|Dick, then using %lower(%1) won't match the name. I'm assuming your names are all stored as lowercase and you just typo'ed it here.
Reply with quote
MNGrizzly
Novice


Joined: 18 Dec 2006
Posts: 47

PostPosted: Sun Feb 18, 2007 5:01 pm   
 
Thanks for taking the time to reply, Larkin.

I tried your change and updated the value of the trigger to:

#IF (%ismember(%lower(%1),@TheInfamous)) {#PCOL gold,firebrick %x1} {#PCOL antiquewhite,firebrick %x1}
#ADDITEM Online %lower(%1)

Now, it colors the first item on the line correctly, but only colors the first item... it stops after the first match.

So, #SHOW Tom, Dick will highlight Tom, but Dick will be unchanged.

Also, just in case it mattered, I included both lines of the trigger here. As you can see, the double parenteses are to build my list of who's online, and I build all my lists with lower case names, so that part is working as intended.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sun Feb 18, 2007 7:21 pm   
 
As I said, it's something that should be corrected in CMUD's behavior, unless we're both just missing some small detail on how this should be coded to fire multiple times per line. The workaround for now would be to capture the entire line from QWHO and parse for the names manually, highlighting as you find them. Not a pretty prospect, but it could work.
Reply with quote
MNGrizzly
Novice


Joined: 18 Dec 2006
Posts: 47

PostPosted: Mon Feb 19, 2007 1:15 am   
 
Ah... I took what you said before to mean an intended change between CMUD and ZMUD, but it sounds now like this is not intended, and possibly a bug that needs addressed.

I've spent enough time banging my head against the desk on this one... I don't feel like gutting it now and starting over. I'll take this up again then in the next release.
Reply with quote
MNGrizzly
Novice


Joined: 18 Dec 2006
Posts: 47

PostPosted: Fri Mar 30, 2007 2:48 pm   
 
I thought I would raise this issue again... this trigger is still not working as I would expect in the latest release. I'm done some putzing around with it, but can't seem to get it to work correctly.

The frustrating thing is, since it is coloring the correct names on each line, I know the trigger is firing each time, but for some reason it only seems to evaluate the value once... Anyone else have any suggestions on how to get this to work?

I did report this as a bug in v1.24, but never heard any feedback nor have I seen it listed in the bug fixes, so I'm assuming Zugg determined this was not truly a CMUD issue.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Mar 30, 2007 4:55 pm   
 
Quote:
so I'm assuming Zugg determined this was not truly a CMUD issue.

No, that's not correct. I have *many* more bugs on my bug list than I can fix in each version. If a bug isn't mentioned in the version history, it doesn't mean that I'm ignoring it, it just means that I haven't gotten to it yet or have deemed it less important (or more complicated to fix) than other bugs. It will take many months to get all of the bugs on my list resolved, so you just need to be patient.

This particular bug has a low priority because it doesn't effect very many people and it's not a bug that is causing a crash or preventing anyone from playing their MUD. There are also several workarounds.
Reply with quote
MNGrizzly
Novice


Joined: 18 Dec 2006
Posts: 47

PostPosted: Sat Mar 31, 2007 11:01 pm   
 
All right, that's encouraging, thank you Zugg. I'm sure you've got more important things on your plate, I figured though it was just as likely my own issue, as I've been known to make my fair share of mistakes coding.

With that said, if you have time, would you mind suggesting one of those workarounds you mentioned?
Reply with quote
MNGrizzly
Novice


Joined: 18 Dec 2006
Posts: 47

PostPosted: Mon Aug 20, 2007 4:46 pm   
 
Curious if this fix is a candidate for the 2.0 release?

If not, if anyone could suggest a workaround, I'd appreciate it. I understand this may not affect many people, but it's an issue I notice daily, and would very much enjoy having this trigger work.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 20, 2007 5:48 pm   
 
Nope, sorry. The problem is that the above issue requires that the trigger itself be executed multiple times on the same line. CMUD is not designed for this. The #CW command itself tries to retest the original trigger to apply it to multiple works on the same line.

So I'm afraid you need to try to find another way to do this. But the rule of thumb is that a given trigger only fires once on any given line and returns the first match that it finds. #CW loops through the rest of the line and colors any words that match the original trigger pattern.
Reply with quote
Thinjon100
Apprentice


Joined: 12 Jul 2004
Posts: 190
Location: Canada

PostPosted: Mon Aug 20, 2007 7:03 pm   
 
I've gotta remember if there's a variable that tells how many matches the trigger regex returns, but if there is, you could quite easily change your regex pattern to support multiple matches on names on a single line "((?:@CityEnemies))(?:\s+((?:@CityEnemies)))*" (change "\s+" to ",\s+" if there are commas)... iterate through the matches and color them individually :)
_________________
If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 20, 2007 8:39 pm   
 
OK, actually, this should make you really happy :)

I was thinking about this at lunchtime, and I realized that I hadn't really looked into the possibility since I switched to the Perl regular expression parser. My old zMUD trigger processor didn't have any way to start matching in the middle of a line. But the Perl RegEx parser has a StartPos argument that tells it where in the string to start testing. So I started wondering if this might be possible after all.

Good news...it turned out to be easy, and actually made the code for #CW and #SUB much more straightforward. So I've added a new trigger option in v2.0 called "Repeat within line". This is a checkbox in the Options down below the "Exclusive" checkbox.

When this checkbox is enabled, then CMUD will loop through the line from the MUD and will keep trying to match your trigger until it gets to the end of the line. I modified the #CW and #SUB commands so that when the "repeat" option is enabled, they only color or replace the subpattern that just matched.

Here is a test I just did in v2.0:
Code:
col=1
#TRIGGER {%w} {#CW @col;#ADD col 1} "" {repeat}

This trigger will color each word in a different color, incrementing the color for each word on the line.

So, your original idea should work in v2.0 with this new Repeat option. Very Happy
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Mon Aug 20, 2007 8:51 pm   
 
Very sweet Zugg. Thanks. Very Happy
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Mon Aug 20, 2007 9:49 pm   
 
Aha, that'll sort out some of my triggers and stop me having to recursively split matches into smaller and smaller chunks
Cool
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Mon Aug 20, 2007 10:35 pm   
 
I <3 Zugg!
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Llwethen
Novice


Joined: 08 Dec 2006
Posts: 37
Location: Lancaster,Oh

PostPosted: Mon Aug 20, 2007 10:45 pm   
 
There are going to be so many options to try in 2.0 we are going to be lost.

Do we get a new 2.0 knowledge base?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Aug 20, 2007 10:59 pm   
 
Yes, the help files will be updated for 2.0, but the documentation will be written after the release (would you be happy if the release was delayed a week just for the docs to be written? I wouldn't). Writing good help files is very difficult, expect it to take some time. Keep your finger on the Get Updates button in the CMUD help.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Aug 20, 2007 11:51 pm   
 
Well hopefully folks, like you, me, nexela, vij, matt et al... will help with that process. I know there are few I'll be documenting as soon as I use them.
_________________
Asati di tempari!
Reply with quote
MNGrizzly
Novice


Joined: 18 Dec 2006
Posts: 47

PostPosted: Thu Aug 23, 2007 5:54 pm   
 
Very cool, thank you! I'm really looking forward to trying that out. I appreciate the dedication.
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