can you Quote a variable name in a match pattern?

Posted by WillFa on Tue 19 Aug 2008 10:00 PM — 7 posts, 17,502 views.

USA #0
If you have a MC variable named enemy, and want to expand that in a trigger's match pattern then,

var.Enemy = "Orc"

"^You (?P<verb>) @Enemy (?P<Predicate>.*)$"
will match:

"You hit Orc very hard."
fine.

However,
"^You (?P<verb>) @Enemy."
doesn't match
"You hit Orc."
because it seems it's taking the "." as part of the variable name.

Is there some sort of
@<Enemy>, @"Enemy", @[Enemy] quoting/delimiting syntax?

Amended on Tue 19 Aug 2008 10:13 PM by WillFa
USA #1
Does @Enemy\. work? Don't have MUSHclient in front of me, but it's just an idea...
USA #2
Nope, it doesn't... and the real pattern I'm trying to match is:

^You (?P<verb>.*?) @Enemy(?:(?: \.)|(?P<predicate>.+))$

and I wouldn't want to escape the regexp's parenthesis anyway. :)
Australia Forum Administrator #3
Works for me:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="^You (?P&lt;verb&gt;.*?) @Enemy(?:(?: \.)|(?P&lt;predicate&gt;.+))$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>verb = %&lt;verb&gt;
predicate = %&lt;predicate&gt;</send>
  </trigger>
</triggers>

<variables>
  <variable name="Enemy">Orc</variable>
</variables>




Test:


You hit Orc hard.
verb = hit
predicate =  hard.


Amended on Wed 20 Aug 2008 12:01 AM by Nick Gammon
USA #4
Why do I always end up asking questions that turn out to have really stupid fixes? (at least I've stopped claiming it was a bug in your code)


I really need to double check while debugging that when I added the trigger, (ctrl+shift+8, alt+a); that I didn't bounce any key strokes.

Cuz, ya know, ctrl+shift+8, alt+a, alt+a ends up

Bringing up the Trigger dialog
Bringing up the Edit Trigger Dialog.
Clearing the enabled flag

side note, you've proved that copying the trigger and pasting the XML into notepad is a good debugging tool.

Umm, can I redeem myself by pointing out that a complete idiot couldn't make:
http://tinyurl.com/59nk9k
Amended on Wed 20 Aug 2008 12:34 AM by WillFa
Australia Forum Administrator #5
Very smooth looking. :-)
USA #6
Thanks for the compliment, Nick. :)

I actually wrote most of it as a lua module (since just making a plugin is very specific to a task/mud/guild(class)).

After the 500 lines in the module, the actual script that makes and populates values is 20 lines. (not bad for 2 windows and 9 "bars".)

I'll be posting it (probably to a blog since only you can do inline images on the forum) after I get done documenting it.