how to implement a zmud function "#cap number"

Posted by Fred on Mon 16 Jan 2006 06:35 AM — 7 posts, 22,826 views.

#0
I want to capture certain lines after a trigger fired.
such as whenever a trigger is fired, it will send the next 5 lines to notepad. Is there any way to implement it?
Australia Forum Administrator #1
The simplest thing is to make a multi-line trigger, like this:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="6"
   match="^whatever matches first line\n.*\n.*\n.*\n.*\n.*\n\z"
   multi_line="y"
   regexp="y"
   send_to="1"
   sequence="100"
  >
  <send>Your response here</send>
  </trigger>
</triggers>


What this is doing is matching the "trigger text" as the first part of the regular expression, followed by 5 lots of .* (anything) followed by a newline.
#2
thanks,it works
but I still have a question.
actually i want to save those lines into a file.
if i use send to log. seems like it will write to file
after i disconnet.. then i try function to write the %0
into file. it always say something like the string is incomplete...
Any idea?
Australia Forum Administrator #3
Did you quote it? Like: "%0"
#4
Ya, I did
even Note("%0") doesnt work
Australia Forum Administrator #5
First, you can simplify the trigger like I do below with:


(.*\n){5}


This makes it more obvious that we want exactly five of the extra lines.

Next, in Lua you can have multi-line literals, so this will work:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="6"
   match="^whatever matches first line\n(.*\n){5}\z"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Note [[%0]]</send>
  </trigger>
</triggers>


The sequence [[ something ]] is a multi-line literal, which can include linebreaks.

An alternative, if you don't want to use Lua (for some reason hehe), is to call a script, like this (in VBscript):


sub mytrigger (name, line, wildcards)
  Note wildcards (10)
end sub


Now the issue of newlines within a quote goes away as this is a variable, not a quoted string.
Amended on Tue 17 Jan 2006 04:26 AM by Nick Gammon
#6
cool
thx for your help.