|
Eyeless Wanderer
Joined: 02 Dec 2001 Posts: 80 Location: Canada
|
Posted: Tue Mar 16, 2004 1:38 pm
%pos, %ismember |
Wondering how to nest %pos with %ismember.
example mud output:
The Wonderfully Ugly Bob is here.
Sadistically Superficial Ted the Antisocial is here.
Where the pre and post titles can change, but the name can't.
(want both to trigger)
OR
Bobbyfisher is here. ///heh, I make joke...
(Don't want trigger)
Trying to make an #IF statement that checks if %n is a member of friends... found a LONG way of doing this, and even tried several ways of combining %pos and %ismember. only long way semi-worked...
#VAR friends Bob|Ted
#IF %pos ("Bob", %1) {blah} {#NOOP}
#IF %pos ("Ted", %1) {blah} {#NOOP} |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Tue Mar 16, 2004 2:15 pm |
Try this:
#if ("%1" =~ {@friends}) {blah} {#noop} |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Tue Mar 16, 2004 3:39 pm |
If you don't want "Bob" to match "Bobbyfisher," try putting a space on either side of "Bob" to make it match the whole word. To put the whole name (with spaces) in the list, you'll need to enclose it in quotes. Otherwise, the spaces will be trimmed when it is added.
#additem friends " Bob "
#additem friends " Ted "
#trigger {{@friends}} {#cw red} |
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Tue Mar 16, 2004 5:15 pm |
Code: |
#trigger {^(*) is here.$} {
#loop %numwords("%1") {
#if %ismember(%word("%1",%i),Bob|Ted) {#cw 47}
}
}
|
|
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Tue Mar 16, 2004 5:22 pm |
Code: |
#trigger {^(*) is here.$} {
#forall bob|ted {
#if %pos(%concat(" ",%i," "),%lower(%concat(" ","%1"," "))) {#cw47}
}
}
|
* non case sensitive |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Tue Mar 16, 2004 6:46 pm |
I wouldn't use Pega's script if you have a lot of items in your friends variable. Better to use the other method.
|
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Tue Mar 16, 2004 7:42 pm |
There are problems in the other method.
These would not match:
quote: Bob Danlo is here.
Danlo Bob, the Mudder is here.
Use my first example, the %pos() one has problems too. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Tue Mar 16, 2004 9:23 pm |
Also, like Larking said, one common solution to this is to match spaces around the name too. However, the spaces are not normally stored inside the string list, instead three triggers are used:
#TRIGGER {^{@friends} } {do stuff}
#TRIGGER { {@friends} } {do stuff}
#TRIGGER { {@friends}$} {do stuff}
This is the traditional solution. However, this three triggers can be modified to better handle punctation. Also, with the new option that allows wildcard inside string list or by using a regulkar expression trigger, this should be made easier too. I'll look more into this and post back with a better trigger set. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue Mar 16, 2004 9:53 pm |
Two-trigger solution.
#TR {^({@Friends})%p*is here} {say Hi %1}
#TR {%p({@Friends})%p*is here} {say Hi %1}
This can be done with a single regex trigger.
#REGEX {b(@Friends)W+.*is here} {say Hi %1}
It should be possible to do a single trigger in zScript, using %q in place of %p, but it doesn't work with parentheses around the stringlist. |
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Tue Mar 16, 2004 10:17 pm |
Half a point to Pega!
Two points to Lightbulb!
Everyone else fails!
|
|
|
|
wilh Wanderer
Joined: 08 Feb 2001 Posts: 89 Location: USA
|
Posted: Tue Mar 16, 2004 11:20 pm |
Where are %p and %q documented? I'm having trouble finding them in the help files.
Wil |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Mar 17, 2004 3:20 am |
Pattern Matching.
|
|
|
|
|
|