Page 1 of 1

Trigger with punctuation.

Posted: Thu Jan 09, 2020 4:47 pm
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.

Re: Trigger with punctuation.

Posted: Sun Jan 12, 2020 5:37 pm
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\.

Re: Trigger with punctuation.

Posted: Tue Jan 14, 2020 9:19 am
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.