|
meddlesome Wanderer
Joined: 24 Aug 2012 Posts: 70
|
Posted: Wed Sep 19, 2012 4:43 am
Conflicting commas in Trigger [SOLVED] |
My Trigger is this...
#TRIGGER {^To the (%*), (%*), (%*)$}
My Test String is this...
To the north by northwest, several miles away, you see the Black Satin. She's heading South by Southwest, and is Anchored. Black Satin is lightly damaged.
My Results are this...
%1 :north by northwest, several miles away
%2 :you see the Black Satin. She's heading South by Southwest
%3 :and is Anchored. Black Satin is lightly damaged.
What I want to be getting is...
%1 :north by northwest
%2 :several miles away
%3 :you see the Black Satin. She's heading South by Southwest, and is Anchored. Black Satin is lightly damaged.
Any ideas on how to get the extra comma to default to the %3 instead of %1? |
|
_________________ Intel Core 2 Quad Q9450 @2.66GHz
MDAC 2.8 SP1 ON WINDOWS XP SP3
Msjet40.dll ver 4.0.9511.0 + Security Bulletin MS08-028
CMUD v237
Order number: **7829
Last edited by meddlesome on Sun Sep 30, 2012 2:05 am; edited 3 times in total |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Wed Sep 19, 2012 6:16 am |
Is the fourth comma always going to be there? You could simply add a fourth (%*) and then concat the %3 and %4.
Or if there is always going to be a 'and is <someword>' You could incorporate that into your pattern. i.e. 'and is Anchored' 'and is Moored' 'and is at sea'
Though I do find that it is odd that it is matching it to the first. You would think the pattern matching would start at the beginning, vs the end of the line. |
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
meddlesome Wanderer
Joined: 24 Aug 2012 Posts: 70
|
Posted: Wed Sep 19, 2012 6:29 am |
No. In fact, most of the trigger lines from the Mud will look like this...
To the south, far off in the distance, you sense a holy place touched by the Gods.
Giving the results of...
%1 :south
%2 :far off in the distance
%3 :you sense a holy place touched by the Gods.
Most trigger lines are having only two commas. This is just one of the few occasions that the trigger line decided to have 3 commas.
I mean, if I have to I can design a routine to deal with it, I just thought it could be dealt with in the trigger line as apposed to having to code a special routine. If I was to do that, I might as well just capture the whole line as one string and work it out manually.
I am definitely not going to split this occurrence into another trigger. |
|
_________________ Intel Core 2 Quad Q9450 @2.66GHz
MDAC 2.8 SP1 ON WINDOWS XP SP3
Msjet40.dll ver 4.0.9511.0 + Security Bulletin MS08-028
CMUD v237
Order number: **7829
Last edited by meddlesome on Wed Sep 19, 2012 6:36 am; edited 1 time in total |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed Sep 19, 2012 6:33 am |
First of all, not sure why you're using (%*). The %* isn't really a pattern-matching variable. It should be (*).
Second, the reason why it's matching so many is because (*) is greedy, and it'll match everything until the other two "matches" are met. For instance, if you had the following line:
Code: |
To the man, yes, you, with the radio, I have to ask, on behalf of everyone here, to please turn it down. |
It would match:
%1: man, yes, you, with the radio, I have to ask
%2: on behalf of everyone here
%3: to please turn it down
You could use regex, which would make matching it a bit easier.
Code: |
^To the ([^\.]+)?, ([^\.]+)?, (.*)$ |
That'd be my way, anyway. |
|
|
|
ins0mnia Novice
Joined: 23 Jan 2011 Posts: 42 Location: United States
|
Posted: Wed Sep 19, 2012 6:33 am |
It can be done with regexp,
#REGEX {^To the (.+?), (.+?), (.*)$} { do_blah } |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Wed Sep 19, 2012 6:37 am |
Also.. out of curiosity.. what MUD is this? An Oceangoing MUD sounds rather neat
|
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Sep 19, 2012 1:02 pm |
Try simply getting rid of the $ at the end of the Zscript trigger:
#TRIGGER {^To the (*), (*), (*)} |
|
|
|
Mumra Wanderer
Joined: 12 Feb 2003 Posts: 93 Location: USA
|
Posted: Wed Sep 19, 2012 1:07 pm |
That won't solve his issue sir. The results are still the same for me duplicating his trigger and test phrase. On 2.37
|
|
_________________ Mumra the Everliving, Realms of Despair
216.251.47.10 Port 4000 |
|
|
|
meddlesome Wanderer
Joined: 24 Aug 2012 Posts: 70
|
Posted: Wed Sep 19, 2012 2:07 pm |
Thanks. I'm not a big Perl enthusiast. Not that I have anything against it, just haven't gotten to using it much. I see that I will have to change that.
That worked well.
This is Medievia. It has grown to encompass ocean activities like harvesting Fae Crabs and trying to keep your ship from being destroyed by mobs ranging from Sea Serpents to Termites. |
|
_________________ Intel Core 2 Quad Q9450 @2.66GHz
MDAC 2.8 SP1 ON WINDOWS XP SP3
Msjet40.dll ver 4.0.9511.0 + Security Bulletin MS08-028
CMUD v237
Order number: **7829 |
|
|
|
meddlesome Wanderer
Joined: 24 Aug 2012 Posts: 70
|
Posted: Wed Sep 19, 2012 4:16 pm |
Perhaps I spoke too soon. I had the first #REGEX start doing the same with
To the north, not far from here, you see a village with a bell tower and a lighthouse, adjacent to a bustling trade post.
I then moved to Rehabs suggestion and not a fix.
I then went to ins0mnia's suggestion and that seems to be holding. I will have to wait and run a few test to see if it hold.
Thanks Guys. The prompt solution will be the easiest to solve this if I can get it too hold. |
|
_________________ Intel Core 2 Quad Q9450 @2.66GHz
MDAC 2.8 SP1 ON WINDOWS XP SP3
Msjet40.dll ver 4.0.9511.0 + Security Bulletin MS08-028
CMUD v237
Order number: **7829 |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Sep 19, 2012 5:19 pm |
If the first regex started doing the same, then the second regex will too, because it is even less specific.
Try this regex:
Code: |
^To the ([^\,]+)?, ([^\,]+)?, (.*)$ |
It is similar to Charneus regex, but I think it fixes a problem. His was trying to grab everything except periods,
mine tries to grab everything except commas. |
|
|
|
ins0mnia Novice
Joined: 23 Jan 2011 Posts: 42 Location: United States
|
Posted: Wed Sep 19, 2012 7:35 pm |
Mine works fine because the ? are inside the parens. Notice the ? don't do anything outside the parens because the block is already being matched to where it won't include commas. Either way works, but it's redundant to do both.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Sep 20, 2012 2:51 am |
Quote: |
Second, the reason why it's matching so many is because (*) is greedy, and it'll match everything until the other two "matches" are met.
|
* is not greedy, in the sense that you can point to say %d or %w and say those two wildcards are not greedy. All Zscript wildcards are equally greedy/ungreedy, and it just so happens that * matches everything whereas the others all have some limiting factor that occurs frequently.
With that said, I think the whole trip-up here is that many (if not most/all) users tend to think that literal text is always matched at the first occurrance of it. That's not true, since Zscript always matches to the broadest width possible.
Quote: |
I see that I will have to change that.
|
Regex is purely optional. There will be on the order of 2 situations where you would need to use it simply because Zscript can't do it at all; the rest are just degrees of ease with zero benefits or penalties to doing it in zscript or regex. In other words, you don't have to learn it if you don't want to (and don't have a compelling reason outside of cmudding to learn it). |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Thu Sep 20, 2012 5:01 am |
Matching the broadest width possible is what being greedy means :P
|
|
|
|
meddlesome Wanderer
Joined: 24 Aug 2012 Posts: 70
|
Posted: Sun Sep 30, 2012 2:07 am |
Well, after sever testing, it seems to be fine. Thanks for the help here.
|
|
_________________ Intel Core 2 Quad Q9450 @2.66GHz
MDAC 2.8 SP1 ON WINDOWS XP SP3
Msjet40.dll ver 4.0.9511.0 + Security Bulletin MS08-028
CMUD v237
Order number: **7829 |
|
|
|
|
|