Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ Tips and tricks
➜ New "send to" option in version 3.83 for scripting omitted lines
New "send to" option in version 3.83 for scripting omitted lines
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Wed 13 Dec 2006 08:48 PM (UTC) Amended on Thu 14 Dec 2006 08:53 PM (UTC) by Nick Gammon
|
Message
| One of the major problems for scripters in MUSHclient seems to be the behaviour of the client, where if you omit a triggered line from output, you cannot also do a world.Note if you use "send to script". This is because any notes (coloured notes, or similar) are also omitted.
The reason for this behaviour is efficiency, as it is easier to omit from the end of the output buffer than from the middle of it. Thus, omitting from output always works backwards from the end of the buffer.
At present the work-around has been to either use a script file, which does not have this problem (as the script execution is deferred until after the lines are omitted), or to delay the new lines slightly by using DoAfterNote.
To make scripting easier, version 3.83 will have a new "send to" option: "Script (after omit)". This is number 14 if you copy the trigger to the clipboard - that is:
send_to="14"
What this does is defer executing the script until after the lines have been omitted. This way, any notes done in the script will be retained.
I have not simply changed the existing behaviour of "send to script" because some scripts may well rely on the sequence in which things are currently done, or rely on the fact that the last line in the output buffer is the matched line.
Now, if you have omitted from output, and then used the new "send to" option, the last line in the output buffer will no longer be the matching line.
To make it easier to process the matching line, if you use Lua scripting, and you have used the new "send to script" option, then a new global variable will be created in your current script space prior to the script being called. This will be named "TriggerStyleRuns", and will be a table of the style runs in the matching trigger.
It will have an entry for each style run, numbered from 1 upwards. Each entry will consist of the following items (the same as when a trigger script is called from Lua):
- "text" - the text of the style run
- "length" - the length of the style run
- "textcolour" - the RGB code for the text of the style
- "backcolour" - the RGB code for the background of the style
- "style" - the style bits (bold is 1, underline is 2, italic is 4)
Even though the line has been omitted already, the usual substitutions of %1, %2 etc. can still be used to refer to captured subpatterns in a regular expression (or wildcards).
In the event that you use the new "send to" functionality, and also have a script name to be executed from your script file, the "send to" is done before the function in your script file. Thus the sequence of events is:
- Do "send to" for things other than "script (after omit)".
- Omit the line from output if required
- Do "send to script (after omit)" - for each matching trigger including each plugin (there may be more than one)
- Call any scripts in the "script" box for any matching triggers
Bear in mind that a particular line from the MUD may generate multiple trigger matches. For one thing, if you use regular expressions and check "repeat on same line" you may get multiple matches. Also, each installed plugin may generate a match on a line.
The deferred "send to script" is done in the order in which the triggers matched, so that if you have multiple matching triggers (either with "keep evaluating" set, or in multiple plugins), then the scripts are queued up for execution in the order in which the original triggers were processed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 13 Dec 2006 09:09 PM (UTC) Amended on Thu 14 Dec 2006 08:53 PM (UTC) by Nick Gammon
|
Message
| As an example of using this, with Lua scripting, this simple trigger takes your prompt line, omits it, and redisplays it in the same colours (the first few lines of the script), and then appends some calculations, to show your percentage of HP and mana:
<triggers>
<trigger
enabled="y"
match="<*/*hp */*m */*mv */*xp>*"
omit_from_output="y"
send_to="14"
sequence="100"
>
<send>
-- display original line with original colours
for k, v in ipairs (TriggerStyleRuns) do
ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
v.text)
end -- for
-- append some calculations
Note (" ", %1/%2 * 100, "%% HP,",
" ", %3/%4 * 100, "%% Mana")
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
6,453 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top