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
➜ Trigger match only the first highlighted word
Trigger match only the first highlighted word
|
You need to log onto the forum to reply or create new threads.
Refresh page
Pages: 1 2
Posted by
| Markomo
(28 posts) Bio
|
Date
| Fri 15 Nov 2024 01:41 PM (UTC) Amended on Fri 15 Nov 2024 01:45 PM (UTC) by Markomo
|
Message
| Hello,
i use this trigger
<triggers>
<trigger
custom_colour="11"
enabled="y"
keep_evaluating="y"
match="\b(?!(Ab|Abends|AP|D|UT|OT|P|Q|Abenteuerlich|Aber|Abermals|Abhanden|Abher|Abhin|Abseits|Absolut|Absonderlicherweise|Absurderweise|Abzueglich|Achtens|Achteraus|Achtern|Achtmal|Aehnlich|Aeusserst|Ah|Aha|Allda|Alldieweil|Alle|Allenaselang|Allenaslang|Allein|Allemal|Allenfalls|Allenthalben|Allerdings|Allerhoechstens|Allerorten|Allerseits|Allerspaetestens|Alleweg|Alleweil|Allgemach|Allig|Allseits|Allzeit|Allzu|Alsbald|Alsdann|Also|Alt|Alters|Altershalber|Am|Amtshalber|An|Anbei|Andante|Andantino|Anderenfalls|Anderenorts|Anderentags|Andererseits|Andernfalls|Andernorts|Anderntags|Anders|Anderswo|Anderweit|Andrerseits|Aneinander|Anfangs|Angst|Anhand|Anjetzt|Anno|Ansatzweise|Anscheinend|Ansonsten|Anstaendigerweise|Anstandshalber|Anstandslos|Anstatt|Anwesend|Apropos|Arschling|Attraktiv|Auch|Auf|Aufgrund|Aufhin|Aufi|Aufmerksam|Aufseiten|Aufwaerts|Aus|Auseinander|Zwischen|Zwischendurch)\b)([A-Z][A-Za-z0-9~'-]*)" <!-- Simple regex: Words only -->
regexp="y"
repeat="y"
send_to="12"
sequence="100"
>
<send>
if _G.parse_active then
-- Get the entire word (highlighted in orange)
local obj = "%0" -- Use %0 to get the entire word found
Note("Found highlighted object: '" .. obj .. "'")
-- Prüfen, ob ein gültiges Objekt erkannt wurde
if not obj or obj == "" then
Note("No valid highlighted object recognised.")
return
end
-- Initialise the list of examined objects, if not available
if not _G.parsed_objects then
_G.parsed_objects = {}
end
-- Check whether the object has already been inspected
if not _G.parsed_objects[obj] then
_G.parsed_objects[obj] = true -- Mark as investigated
Execute("b " .. obj)
Note("Objekt '" .. obj .. "' is being investigated.")
else
Note("Objekt '" .. obj .. "' has already been analysed.")
end
else
if not _G.warned_about_inactive then
Note("Parsing is not active. Please start with 'reset_b'")
_G.warned_about_inactive = true
end
end
</send>
</trigger>
</triggers>
The main problem is now. The trigger match only the first highlighted word.
https://ibb.co/ZWsTbgV
What am I doing wrong?
BR
PS: The RegEx trigger works perfectly -> https://ibb.co/MhNP3fH | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 15 Nov 2024 09:08 PM (UTC) |
Message
| Those screenshots are hard to read.
You don't need to put _G. in front of every global variable. If they are not declared local they are assumed to be global.
What are you expecting to see, exactly?
Repeating on the same line is for colouring words, not for executing the script multiple times. If you want to do something multiple times on one line, do that in the script itself (eg. do string.gmatch and then do the action you want on every match). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #2 on Fri 15 Nov 2024 10:29 PM (UTC) |
Message
|
Nick Gammon said:
Those screenshots are hard to read.
You don't need to put _G. in front of every global variable. If they are not declared local they are assumed to be global.
What are you expecting to see, exactly?
Repeating on the same line is for colouring words, not for executing the script multiple times. If you want to do something multiple times on one line, do that in the script itself (eg. do string.gmatch and then do the action you want on every match).
Thank you for your reply.
I want if it says "You see a tree and a house and a car." then the regex-trigger should colour "tree, house, car and I want the script to execute my commands tree, house, car.
Currently, however, it only does this for the first object. In my example "tree", it then cancels and goes to the next line.
BR | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sat 16 Nov 2024 09:18 PM (UTC) Amended on Sat 16 Nov 2024 09:20 PM (UTC) by Nick Gammon
|
Message
| This should work for you:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^.*\b(@!objects)\b.*$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
for word in string.gmatch ("@objects", "%a+") do
if string.match ("%0", "%%f[%%a]" .. word .. "%%f[%%A]") then
Send ("examine " .. word)
end -- if
end -- for
</send>
</trigger>
</triggers>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
Now you need to put the words you are looking for into a variable named "objects" in (World configuration -> Scripting -> Variables), for example:
<variables>
<variable name="objects">tree|house|car</variable>
</variables>
Each word needs to be separated by a "|" symbol, like above. What the trigger does is match any of those words, and, if found, then runs the script that searches for all of those words in the matching text and examines each one it finds. The stuff about %%f is for a "frontier" pattern which basically restricts matches to a word boundary.
Test
I see a treehouse, house and car here.
examine house
examine car
It examined the house and car but not the treehouse because that was not a word on its own. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #4 on Mon 18 Nov 2024 02:41 AM (UTC) Amended on Fri 22 Nov 2024 03:04 AM (UTC) by Nick Gammon
|
Message
| Interesting approach, but unfortunately that doesn't help me, because I want all the words highlighted in orange to be looked at. Otherwise I would have to extract the words from each room in order to explore them. I thought Mushclient would offer a function that can automatically capture highlighted words.
I still hope that you have a more practical approach for me. As you have seen in my screenshot, there is a lot of text and "German" is a difficult language ;)
Thanks Nick! | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Mon 18 Nov 2024 03:59 AM (UTC) |
Message
| In what way does my solution not work for you? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #6 on Mon 18 Nov 2024 12:09 PM (UTC) |
Message
|
Nick Gammon said:
In what way does my solution not work for you?
You wrote that I would have to put every single word into a variable. The texts of all the rooms in my mud are far too different for that.
Quote:
Now you need to put the words you are looking for into a variable named "objects" in (World configuration -> Scripting -> Variables), for example:
<variables>
<variable name="objects">tree|house|car</variable>
</variables>
Each word needs to be separated by a "|" symbol, like above. What the trigger does is match any of those words, and, if found, then runs the script that searches for all of those words in the matching text and examines each one it finds. The stuff about %%f is for a "frontier" pattern which basically restricts matches to a word boundary.
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #7 on Mon 18 Nov 2024 08:32 PM (UTC) Amended on Mon 18 Nov 2024 08:33 PM (UTC) by Nick Gammon
|
Message
| I don't understand the difficulty here. You already have all the words in your first post. All you have to do is make a variable (in the World configuration -> Scripting -> Variables) named "objects" and copy/paste the words into it:
Ab|Abends|AP|D|UT|OT|P|Q|Abenteuerlich|Aber|Abermals|Abhanden|Abher|Abhin|Abseits|Absolut|Absonderlicherweise|Absurderweise|Abzueglich|Achtens|Achteraus|Achtern|Achtmal|Aehnlich|Aeusserst|Ah|Aha|Allda|Alldieweil|Alle|Allenaselang|Allenaslang|Allein|Allemal|Allenfalls|Allenthalben|Allerdings|Allerhoechstens|Allerorten|Allerseits|Allerspaetestens|Alleweg|Alleweil|Allgemach|Allig|Allseits|Allzeit|Allzu|Alsbald|Alsdann|Also|Alt|Alters|Altershalber|Am|Amtshalber|An|Anbei|Andante|Andantino|Anderenfalls|Anderenorts|Anderentags|Andererseits|Andernfalls|Andernorts|Anderntags|Anders|Anderswo|Anderweit|Andrerseits|Aneinander|Anfangs|Angst|Anhand|Anjetzt|Anno|Ansatzweise|Anscheinend|Ansonsten|Anstaendigerweise|Anstandshalber|Anstandslos|Anstatt|Anwesend|Apropos|Arschling|Attraktiv|Auch|Auf|Aufgrund|Aufhin|Aufi|Aufmerksam|Aufseiten|Aufwaerts|Aus|Auseinander|Zwischen|Zwischendurch
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #8 on Tue 19 Nov 2024 02:33 AM (UTC) |
Message
|
Nick Gammon said:
I don't understand the difficulty here. You already have all the words in your first post. All you have to do is make a variable (in the World configuration -> Scripting -> Variables) named "objects" and copy/paste the words into it:
Ab|Abends|AP|D|UT|OT|P|Q|Abenteuerlich|Aber|Abermals|Abhanden|Abher|Abhin|Abseits|Absolut|Absonderlicherweise|Absurderweise|Abzueglich|Achtens|Achteraus|Achtern|Achtmal|Aehnlich|Aeusserst|Ah|Aha|Allda|Alldieweil|Alle|Allenaselang|Allenaslang|Allein|Allemal|Allenfalls|Allenthalben|Allerdings|Allerhoechstens|Allerorten|Allerseits|Allerspaetestens|Alleweg|Alleweil|Allgemach|Allig|Allseits|Allzeit|Allzu|Alsbald|Alsdann|Also|Alt|Alters|Altershalber|Am|Amtshalber|An|Anbei|Andante|Andantino|Anderenfalls|Anderenorts|Anderentags|Andererseits|Andernfalls|Andernorts|Anderntags|Anders|Anderswo|Anderweit|Andrerseits|Aneinander|Anfangs|Angst|Anhand|Anjetzt|Anno|Ansatzweise|Anscheinend|Ansonsten|Anstaendigerweise|Anstandshalber|Anstandslos|Anstatt|Anwesend|Apropos|Arschling|Attraktiv|Auch|Auf|Aufgrund|Aufhin|Aufi|Aufmerksam|Aufseiten|Aufwaerts|Aus|Auseinander|Zwischen|Zwischendurch
Ah, I understand the confusion now. All these words are an exclusion list and not words that are marked in orange. This is appropriate at the end of the regex.
<triggers>
<trigger
custom_colour="11"
enabled="y"
keep_evaluating="y"
match="\b(?!(Ab|any number of other words|Zwischendurch)\b)([A-Z][A-Za-z0-9~'-]*)"
regexp="y"
repeat="y"
send_to="12"
sequence="60"
>
</trigger>
</triggers>
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Tue 19 Nov 2024 04:32 AM (UTC) |
Message
| Just to be clear then, you want to examine every word on every line that arrives, unless it is in your exclusion list? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #10 on Tue 19 Nov 2024 11:02 PM (UTC) |
Message
|
Nick Gammon said:
Just to be clear then, you want to examine every word on every line that arrives, unless it is in your exclusion list?
Yes. All orange highlighted words | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #11 on Wed 20 Nov 2024 05:37 AM (UTC) Amended on Wed 20 Nov 2024 05:39 AM (UTC) by Nick Gammon
|
Message
| OK, so assuming you set up the "objects" variable as described above (your exclusion list) then this should do it:
<triggers>
<trigger
enabled="y"
match="*"
send_to="12"
sequence="100"
>
<send>
local input_line = [===[%0]===]
local exclusions = { }
-- build table of exclusion words
for word in string.gmatch (GetVariable ("objects"), "%a+") do
exclusions [word] = true
end -- for each excluasio
for word in string.gmatch (input_line, "[A-Z][A-Za-z0-9~'%-]+") do
if not word [exclusions] then
Note ("examine " .. word)
end -- if
end -- for
</send>
</trigger>
</triggers>
What that does is process every word of every line, looking for words starting with a capital (uppercase) letter, and then check against the exclusion list. If not found, it examines it.
Test:
Die schweren Antriebe enes Raungleiters dreohnen laut itgendwo am nordoestlichen Himmel
examine Die
examine Antriebe
examine Raungleiters
examine Himmel
Forgive me if I misspelt some of your German words, the screenshot was very hard to read. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #12 on Wed 20 Nov 2024 08:20 PM (UTC) Amended on Fri 22 Nov 2024 03:02 AM (UTC) by Nick Gammon
|
Message
| You don't have to apologise for anything. I am very grateful that you are taking the time. The trigger option with * is not an option, because otherwise the trigger takes everything and I also have to extend the exclusion list with the prompt and special characters and other mud-specific stuff. This might generate endless loops. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #13 on Fri 22 Nov 2024 03:03 AM (UTC) |
Message
| If you want to match only certain lines then you have to specify, somehow, which lines are going to be tested and which ones are not, which I don't see you doing in your original post. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Markomo
(28 posts) Bio
|
Date
| Reply #14 on Fri 22 Nov 2024 06:48 PM (UTC) |
Message
|
Nick Gammon said:
If you want to match only certain lines then you have to specify, somehow, which lines are going to be tested and which ones are not, which I don't see you doing in your original post.
That's right. I thought that was logical, as I only wanted to highlight all the orange-coloured words. Hence the problem where I said "it only takes the first word of each line".
if _G.parse_active then
-- Get the entire word (highlighted in orange)
local obj = "%0" -- Use %0 to get the entire word found
Note("Found highlighted object: '" .. obj .. "'")
So you don't have a solution to my problem? | 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.
2,549 views.
This is page 1, subject is 2 pages long: 1 2
You need to log onto the forum to reply or create new threads.
Refresh page
top