Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ how to checking contents of next line received

how to checking contents of next line received

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jing Wu   Australia  (35 posts)  Bio
Date Tue 20 May 2008 08:02 PM (UTC)
Message
Hi,

Im look for a way to check the next line recevied after a trigger executed.

For example:
here is a trigger: ^Andy says xxx
and it is triggered.
i need to check the next line after this trigger to decide what commands will be sent.
so i got two questions:
1. how to obtain current line num. of this trigger?
2. how to check the next line of this trigger?

if I am able to get the line num.(lineNum) and use
GetLineInfo(lineNum + 1, 3). In this time, the new line might not be recevied from the server, will it return nil?
Or I can set a callback function which will be executed once (lineNum + 1) line is recevied?

Thanks!


Kernel Development
Top

Posted by Beale   (35 posts)  Bio
Date Reply #1 on Tue 20 May 2008 09:58 PM (UTC)
Message
Instead of this (rather complicated-sounding) method, you could make a catch-all trigger that is enabled by the first trigger and which disables itself.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 20 May 2008 10:43 PM (UTC)
Message
You certainly can't obtain the contents of line+1 because it hasn't arrived yet. Triggers fire as soon as a line arrives.

However one solution is a multi-line trigger, see example below. It depends a bit on what is in the second line, I have assumed anything as you didn't say.

This trigger will fire after the second line arrives, and will check that the first line is "Andy says <something>".


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^Andy says (.+)\n(.+)\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>
%%1 is %1
%%2 is %2
</send>
  </trigger>
</triggers>


See http://mushclient.com/pasting for how to copy that into the client.

As Beale says, another approach is for the first trigger to enable a "catch-all" trigger (ie. matching "*") which is initially disabled. This second trigger then knows that it must have followed the "Andy says" line. The second trigger then disables itself. The FAQ at http://mushclient.com/faq has an example of this sort of thing in point 37.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jing Wu   Australia  (35 posts)  Bio
Date Reply #3 on Wed 21 May 2008 08:37 AM (UTC)
Message
Thanks Nick.
It's a good idea to use multi-line trigger, which is an easy way to reach my purpse.
Originally, i was thinking about using plugin with "OnPluginLineReceived" callback, but it seems i need to write lots of codes.

Kernel Development
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,175 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.