Multiline trigger issues

Posted by Keberus on Sun 03 Jan 2010 06:05 PM — 4 posts, 16,222 views.

#0
Okay, I have multi-line prompt and I want to capture some info from each line, the prompt looks something like so:


Force 2000/2000  Align 530  Mail 0/9 Room#<109>
Hp:1000/1000  Move:1000/1000  Gold:9,744,232 <>


I am trying to pull Force stats, hp, and movement. I have written a few triggers to test this which work, separately. They look like so:

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="^Force (\d+)\/(\d+)"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("curr_force", "%1" )
SetVariable("max_force", "%2" )</send>
  </trigger>
</triggers>


and:

<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^Hp\:(\d+)\/(\d+)  Move\:(\d+)\/(\d+)"
   name="hp"
   regexp="y"
   send_to="3"
   sequence="100"
  >
  <send>Hit Points %1/%2 ...Move %3/%4</send>
  </trigger>
</triggers>


They both work fine separately, but I can't seem to get them to combine right I've tried this:

<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^Force (\d+)\/(\d+)*Hp\:(\d+)\/(\d+)  Move\:(\d+)\/(\d+)"
   multi_line="y"
   regexp="y"
   send_to="3"
   sequence="100"
  >
  <send>Fp %1/%2 Hit Points %3/%4 ...Move %5/%6</send>
  </trigger>
</triggers>


I have also tried many versions of the above with different combos of * and \n...to no avail. If someone could show me what I'm doing wrong it would be much appreciated.

Thanks,
KeB
Amended on Sun 03 Jan 2010 06:06 PM by Keberus
Australia Forum Administrator #1
I presume there is a typo in the last example, and that:


*Hp


should read:


.*Hp


Otherwise it will certainly not behave as you expect, since I gather you are trying to skip various stuff you are not interested in.

Basically you need to turn on the "dot matches all" option, otherwise newlines are not caught in the .* sequence.

The version below works for me:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="(?s)^Force (\d+)\/(\d+).*Hp\:(\d+)\/(\d+)  Move\:(\d+)\/(\d+)"
   multi_line="y"
   regexp="y"
   send_to="3"
   sequence="100"
  >
  <send>Fp %1/%2 Hit Points %3/%4 ...Move %5/%6</send>
  </trigger>
</triggers>

Amended on Sun 03 Jan 2010 07:42 PM by Nick Gammon
USA #2
Right, the * symbol has different meanings depending on whether you have regular expressions enabled for the trigger. With it off, it will match a single word, but when regex is enabled, it's a flag that means "zero or more of the preceeding character".
#3
Sorry, it wasn't a typo. I didn't realize that I needed .* instead of just *. Thanks again for the help Nick.