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 ➜ Plugins ➜ OnPluginLineReceived and substitution

OnPluginLineReceived and substitution

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


Posted by tobiassjosten   Sweden  (79 posts)  Bio
Date Sat 28 Mar 2009 04:40 PM (UTC)
Message
I tried adding a couple of thousand triggers with regexp patterns and then subjected myself to lots of output, to test whether this would be viable. It wont be, as I could actually "feel" the difference between testing with those triggers loaded and not. So I'm pondering ways to still harness the power of MUSHclient while keeping to my old Lua pattern matching, which I used to do in IMTS (aka Whyte's "Mudbot") and which is way faster than regexp.

The OnPluginLineReceived callback looks really nice for this and I've already implemented its usage in my trigger abstraction. The only problem I'm facing now is with text substitution. If I let the callback return false, nothing is apparently displayed - not even my own Notes.

If I put the Notes on a timer (which might be running their own thread?) it works, but this is a sloppy solution so I'm looking for something else.

So.. Is OnPluginLineReceived supposed, by design or intent, to work like this? Are there any ways around it?

Simplicity is Divine | http://nogfx.org/
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 28 Mar 2009 07:56 PM (UTC)
Message
First, let's examine ways of making standard trigger processing more efficient.


  • Do not check "keep evaluating" unless absolutely necessary. With "keep evaluating" unchecked, as soon as a trigger matches, it stops evaluating other triggers, thus if the first trigger out of a thousand matches, it only has to do one regexp compare, not a thousand.

  • Order your triggers, by sequence number, from lowest (most likely to match) to highest (least likely to match). Thus if you often get (say) a prompt line, if that has a low sequence number (like 10) then it gets tested first, thus eliminating the need to check all the other triggers. A bit of evaluating using GetTriggerInfo (selector 21) will tell you, after playing for a while, which ones match most often.

  • Do not check "expand variables" unless absolutely necessary. When checked, the regular expression has to be "compiled" every time (as it may have changed), thus slowing down the regular expression matching.

  • Do not use "send to script" but rather put a script function name into the Script box, and use a script file. Using "send to script" means the script has to be compiled by Lua every time, and then executed. Using a script file, the script only ever gets compiled once.

  • Make your regular expressions more specific, where possible, thus allowing the regular expression state engine to match faster. For example, instead of:

    
    ^You see .* here\.$
    


    use:

    
    ^You see [A-Za-z]+ here\.$
    


  • Enable/disable groups of triggers depending on the context. For example, if a whole batch of triggers are only used in combat, put them in a group and use EnableTriggerGroup to enable them when you enter combat, and disable them after combat, thus speeding up matching because triggers that can't match, aren't evaluated.


Quote:

If I put the Notes on a timer (which might be running their own thread?) it works, but this is a sloppy solution so I'm looking for something else.


Not in a separate thread, but timers are evaluated periodically in the main loop.

Quote:

Is OnPluginLineReceived supposed, by design or intent, to work like this? Are there any ways around it?


It was designed to work that way, yes.

Two things you could do ...


  1. Make a single trigger, matching on "*" and omit from output. Then pass this to your script which runs your Lua pattern matching on it. Use the technique described in http://mushclient.com/faq point 23 to recreate the lines in the output window (before or after substitution) in the original colours, or altered ones.

    Effectively this turns the output window into notes, but they could look the same as the original.

  2. Use OnPluginPacketReceived plugin callback. This actually lets you modify the packets, and thus you can change things as much as you want. The disadvantage here is that packets are supplied prior to processing for colour codes (and telnet codes etc.), and line boundaries and packet boundaries are not necessarily the same.

    To make this work you really need to batch up packets until you have a completed line (there are examples on the forum), and then take each complete line and process it further. If you just want to make fairly simple changes, you could do that, then pass the changed packet on, and let MUSHclient keep decoding colours. Or, you could handle everything yourself, and use Note (or ColourNote) to put all the text on the screen.

    However in this case I think my first suggestion achieves much the same result with less effort.



- Nick Gammon

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

Posted by tobiassjosten   Sweden  (79 posts)  Bio
Date Reply #2 on Tue 31 Mar 2009 05:44 AM (UTC)
Message
Those are excellent suggestions for speeding up your triggers! Perhaps good enough to sticky somewhere as optimization tips?

Either way, I don't need the extra goodies that regexp brings and feel it's an unnecessary cost. Largely also because I prefer to use multiple triggers to match the same server output, just put in different places depending on use. Say a trigger for the notice of being enemied to a city. In my "diplomat tracker module", I want a trigger to keep score of my relations, but I also want another trigger to fire within my "visual module", so that I may color it red. Seperation of concern.

I'm currently toying around with the OnPluginPacketReceived callback and it looks awesome! I have come quite a bit but I still need to figure out how to best make its abstraction layer easy to use, while keeping the power of having ANSI and telnet negotiations in there.

Thanks for your great support, Nick!

Simplicity is Divine | http://nogfx.org/
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.


15,353 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.