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
➜ Lua
➜ Matching two lines of text
Matching two lines of text
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Blixel
(80 posts) Bio
|
Date
| Mon 04 Sep 2017 04:02 PM (UTC) |
Message
| I'm trying to set up a regular expression that will suppress output to the screen of the following text:
I'm able to do this if I set up 2 triggers. The first one looks for:
And the second one looks for:
I should be able to do this with 1 trigger, but I can't seem to figure out what's missing. I've tried:
^\>?say openthechest$\n[*][*][*]$
and
^\>?say openthechest\n[*][*][*]$
and
^\>?say openthechest$\r\n[*][*][*]$
and
^\>?say openthechest\r\n[*][*][*]
...but I can't seem to capture both lines in one trigger.
https://i.imgur.com/Q8vqU1r.jpg | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 05 Sep 2017 06:54 AM (UTC) |
Message
| There are multi-line trigger, but they don't let you omit the lines from output.
You could use a multi-line trigger, and then the DeleteLines function to delete two lines.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #2 on Tue 05 Sep 2017 03:55 PM (UTC) |
Message
|
Nick Gammon said:
There are multi-line trigger, but they don't let you omit the lines from output.
You could use a multi-line trigger, and then the DeleteLines function to delete two lines.
Ok, I got the multi-line trigger working finally. I verified it was working by just putting a Note() out to the screen. But I'm not sure how to get DeleteLines() function to work. The link you posted says it can't be used in a Trigger. So placing DeleteLines(2) in the trigger won't delete the previous 2 lines. So how do you use it then? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 05 Sep 2017 09:53 PM (UTC) |
Message
| See the help for that function:
Quote:
Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work. In version 3.76 you will cause the client to crash if you do this. In version 3.77 upwards it will silently fail (ie. do nothing).
If you want to call DeleteLines from a trigger you must call a function in your script file (or plugin script), not directly from send-to-script.
In other words, make a script file, put a function into it, and put the name of the function in the trigger as the script to be called. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #4 on Tue 05 Sep 2017 10:23 PM (UTC) Amended on Tue 05 Sep 2017 11:04 PM (UTC) by Blixel
|
Message
|
Nick Gammon said:
See the help for that function:
Quote:
Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work. In version 3.76 you will cause the client to crash if you do this. In version 3.77 upwards it will silently fail (ie. do nothing).
If you want to call DeleteLines from a trigger you must call a function in your script file (or plugin script), not directly from send-to-script.
In other words, make a script file, put a function into it, and put the name of the function in the trigger as the script to be called.
First, I apologize for my ignorance as I realize this seems brain-numbingly simple to you.
I created a script called deleteLines.lua which now contains the following:
function deleteTwoLines()
DeleteLines(2)
end
I assume I have to go to World Properties -> Scripting -> Scripts and include that script as an External Script File.
Then, I've gone to my Multi-line trigger and added the line deleteTwoLines() so that it will call the function I created.
I know the trigger is being, well, triggered, because I have a Note("Trigger is working") which I can see on the output. However, the 2 lines that I am trying to omit are not being omitted.
So there is still some part of this brain-numbingly simple problem that I am too ignorant to sort out. Apologies once again for my intellectual inferiority.
EDIT: I'm wondering if this would be better http://www.gammon.com.au/forum/?id=10453 ... using CallPlugin instead of an external script? (Since there can apparently only be 1 external script, but you can have as many plugins as you want as far as I can tell.)
I'm trying to make this plugin:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, September 05, 2017, 7:37 PM -->
<!-- MuClient version 5.05 -->
<!-- Plugin "deleteTwoLines" generated by Plugin Wizard -->
<muclient>
<plugin
name="deleteTwoLines"
author="muclient"
id="6eb408421deaede0c6a61a36"
language="Lua"
purpose="Deletes the last 2 lines from the output display"
date_written="2017-09-05 19:36:11"
requires="5.00"
version="1.0"
>
</plugin>
<!-- Script -->
<script>
<![CDATA[
function OnPluginPacketReceived (s)
end -- OnPluginPacketReceived
]]>
function deleteTwoLines ()
DeleteLines(2)
end -- deleteTwoLines
</script>
<!-- Get our standard constants -->
<include name="constants.lua"/>
</muclient>
And then I'm having my trigger call it with:
CallPlugin ("6eb408421deaede0c6a61a36", "deleteTwoLines")
It's not working ... but it seems like this would be the superior option if I can get it working. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Tue 05 Sep 2017 11:21 PM (UTC) |
Message
| It works:
<triggers>
<trigger
enabled="y"
lines_to_match="2"
match="^foo\nbar$"
multi_line="y"
regexp="y"
script="deleteTwoLines"
sequence="100"
>
</trigger>
</triggers>
 |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
You can't call deleteTwoLines inside send-to-script, you have to put the function name in the script box. Paste that trigger and you'll see what I mean.
I doubt if the plugin method will work because you will have to call that from send-to-script which hits the issue of not using send-to-script. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #6 on Tue 05 Sep 2017 11:47 PM (UTC) |
Message
|
Nick Gammon said:
It works:
You can't call deleteTwoLines inside send-to-script, you have to put the function name in the script box. Paste that trigger and you'll see what I mean.
Ok this does work, though it seems to introduce a new issue. I can live with it though if I have to. But the way I've been using this is to call EnableTrigger() just before and after the trigger to turn it on and then back off. That way it only gets activated during the few milliseconds that is required for muclient to hide the unwanted text. But now that I'm sending to World instead of Script, I don't have a way to shut that trigger back off after it's called. Right?
In this case, that is probably ok. The text that activates the trigger isn't something that would normally appear. But for the sake of completeness, I do like the idea of only having these kinds of triggers activated at the very moment they are being used, and then instantly shut back off.
Nick Gammon said: I doubt if the plugin method will work because you will have to call that from send-to-script which hits the issue of not using send-to-script.
I see. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #7 on Wed 06 Sep 2017 07:13 AM (UTC) Amended on Wed 06 Sep 2017 07:14 AM (UTC) by Nick Gammon
|
Message
|
Quote:
I don't have a way to shut that trigger back off after it's called.
You can send to script, and turn the trigger off, sure. Just don't do the DeleteLines that way.
Of course, the script function you call could do that anyway. Why not? |
- 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.
23,992 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top