Trigger with punctuation.

Post Reply
sofkey
Posts: 4
Joined: Thu Jan 09, 2020 4:16 am

Trigger with punctuation.

Post by sofkey »

My trigger text is perl regex:

^You receive (.*) experience.

So, when I kill an enemy and receive this line, it does things like look in the corpse, get gold, etc.

You receive 288 experience.

However, GNS Mud where I just started playing also awards skill experience so we get this line:

You receive 100 experience points for your successful use of skills.

My trigger is also firing on this line. Why is that happening? There's a period punctuation mark in the trigger text so I don't understand why it's triggering on the MUD line without the period.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Trigger with punctuation.

Post by demonnic »

Because in regex a period means "any character". If you want to match a literal period, you need to escape it. You even used the "any character" property of the period earlier in the pattern.

Code: Select all

^You receive (.*) experience\.

tarkenton
Posts: 30
Joined: Thu Feb 07, 2013 7:33 am

Re: Trigger with punctuation.

Post by tarkenton »

Honestly, I'd just close it out properly if it's a single line like it looks like.

Code: Select all

^You receive (\d+) experience\.$
if you want to capture the number amount of experience.

Code: Select all

^You receive \d+ experience\.$
if you don't care about the number amount of experience.

The reason it kept is you didn't signal the end of line with $. That forces it to match the above line, no more.. Without it, you could have something like

Code: Select all

You receive 100 experience points for your successful use of skills and become super buff, wise, and as powerful as Merlin because really, he's the ultimate wizard and that's why we play MUDs right?
match just fine because you're not telling your regex to look for the end of the line. As long as it matches the first half, then that's good enough for the engine. It's the same idea as if you'd set the trigger type to beginning of line, and your trigger as You receive.

Post Reply