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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Neco
Newbie


Joined: 24 Jun 2006
Posts: 6

PostPosted: Mon Jun 04, 2007 6:21 am   

Tricky trigger
 
I'm trying to make a trigger that will capture three things. Specific pipe number, type of item in the pipe, and number of puffs left in the pipe. Here's what I have so far:

Output from mud:

artfct pipe77788 skullcap292048 a skullcap flower ( 10 puffs)
artfct pipe88555 slippery elm51716 slippery elm ( 10 puffs)
artfct pipe1114 valerian46354 a valerian leaf ( 10 puffs)

My trigger:
#TRIGGER {artfct*pipe(%d)%s(%w)*{elm|skullcap|valerian}*~(%s%3%spuffs~)} {
#var pipe%2 %1
#var pipe%2_count %3
}

So @pipeskullcap= 77788 and @pipeskullcap_count= 10. The trigger works great on both skullcap and valerian. However, it always captures %2 as 'slippery'. Is there anyway I can have it capture elm instead of slippery?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Jun 04, 2007 6:31 am   
 
As a general rule, in order to get the most specific matches from your triggers as possible, you should use as few * characters as you can manage. The more exact you make your pattern, the less likely it is to cause problems. Also, it's possible that the forums have eaten some of the spacing. If they have, you'll find that any trigger patterns you're given won't work - use [code] tags to preserve the spacing and you should be okay.

That said, this is a slightly different case, and * is unique in that it can match 0 characters. this allows you to easily match both the word "slippery" and the absence of the word. You could also use {slippery|} instead, if you chose. If you were using a regex, I'd advising using some sort of character range with the + character, or even an optional part of the pattern but for zMUD triggers, * will serve the purpose. How about something like this?

artfct pipe(%d)*(%w)%d {a skullcap flower|slippery elm|a valerian leaf} ~( (%d) puffs~)

Assuming that the forums have eaten some of the spacing here, if you need addition spacing, don't use * but replace the spaces in the pattern with %s.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Neco
Newbie


Joined: 24 Jun 2006
Posts: 6

PostPosted: Mon Jun 04, 2007 7:00 am   
 
Thanks for the reply,

The troublesome part is where there's an extra word in the elm line. I can only get it to capture the first word, is there a way I can get it to ignore that one, and simply capture elm, in place of slippery? Yes, as you stated I could easily use the first word slippery with {slippery|}, but that's what I'm trying to get around. I can't seem to get it to match with elm, despite my efforts in using *. This is just a simple zmud trigger, since my regex experience is about non-existent.

Here's the output again.

artfct pipe77788 skullcap292048 a skullcap flower ( 10 puffs)
artfct pipe88555 slippery elm51716 slippery elm ( 10 puffs)
artfct pipe1114 valerian46354 a valerian leaf ( 10 puffs)
Reply with quote
Neco
Newbie


Joined: 24 Jun 2006
Posts: 6

PostPosted: Mon Jun 04, 2007 7:45 am   
 
Well, I found a solution. Thanks to Larkin, for his work. I took a look at his Acropolis system http://larkin.dischai.googlepages.com/acropolis.txt ..and found a way to use regex to capture it perfectly.



^\s*(lit|out|artfct)\s+pipe(\d+)\s+(?:\w+\s)?(elm|skullcap|valerian)\d+.+?\s+\(\s+(\d+) puffs\)$

I'll use this, and Thanks again goes to Larkin for sharing his code. Still, I wonder: Is there a way to do it with a zmud trigger?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Jun 04, 2007 8:17 am   
 
Not easily - I didn't realise that the * would be greedy in my trigger above, which causes problems. If there were a way to set the greediness of the wildcard, it'd be easy.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zhiroc
Adept


Joined: 04 Feb 2005
Posts: 246

PostPosted: Tue Jun 05, 2007 12:24 am   
 
Fang Xianfu wrote:
Not easily - I didn't realise that the * would be greedy in my trigger above, which causes problems. If there were a way to set the greediness of the wildcard, it'd be easy.

Usually, once a trigger pattern gets complicated enough, I switch to a regex trigger. "*" is greedy, "*?" is non-greedy.
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Tue Jun 05, 2007 9:19 am   
 
Hmmm. This is way more complicated than it needs to be. There are a couple of very simple solutions:

Solution 1:
#TRIGGER {artfct%spipe(%d)*({elm|skullcap|valerian})*~(%s%3%spuffs~)} {
#var pipe%2 %1
#var pipe%2_count %3
}

Solution 2:
#TRIGGER {artfct%spipe(%d)* (%w)%d *~(%s%3%spuffs~)} {
#var pipe%2 %1
#var pipe%2_count %3
}

In solution one, I've placed parentheses around the string list you're matching, ie the {elm|skullcap|valerian}. Doing this, puts the matching string into a variable. In this case, into the variable %2.
In solution two, I've placed the word immediately PRECEDING the number into the variable, rather than the first word AFTER the first number, into the variable %2.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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