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
➜ General
➜ Help with Lua: Detecting First Instance of Colored Text
Help with Lua: Detecting First Instance of Colored Text
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Aeagle
(1 post) Bio
|
Date
| Sat 09 Mar 2024 04:19 PM (UTC) Amended on Sat 09 Mar 2024 04:20 PM (UTC) by Aeagle
|
Message
| My situation is as follows:
I have multiple nearly identical lines, with different colors. I want to grab the first instance of a particular text color (white). For example:
inventory:
a small chest (text color = black)
a big chest (text color = white)
a chest (text color = black)
a chest (text color = white)
I would like to automatically generate the output "open 2.chest" based on these lines.
I have written a trigger that matches on chest, and calls the Lua Script, which tells me the color of the text. Unfortunately, I don't know how to expand this logic to generate the relative position so this might not be the right strategy. I would also prefer not to use multi-line triggers either if possible because I found that they interfere with other triggers sometimes.
Thanks!
function GetFirstColoredItem(name, line, wildcards, styles)
local firstStyle = styles[1]
local textColor = firstStyle.textcolour
end | Top |
|
Posted by
| Nick Gammon
Australia (23,072 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 09 Mar 2024 11:54 PM (UTC) |
Message
| Triggers can match on the first colour in the line, so a simple solution would be to make your trigger match white text.
See:
... for how you might detect an inventory, without using a multi-line trigger. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,072 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 10 Mar 2024 02:52 AM (UTC) |
Message
|
Aeagle said:
I have written a trigger that matches on chest, and calls the Lua Script, which tells me the color of the text. Unfortunately, I don't know how to expand this logic to generate the relative position so this might not be the right strategy.
If you follow the FAQ I mentioned above, all you would need to do is set a variable on the "Inventory" line to indicate you haven't yet opened something, and then when the first white line comes, change the variable to show you have opened it. That way you open the first one. |
- 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.
1,667 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top