[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  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] Refresh page


Posted by Aeagle   (1 post)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] 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:

Template:faq=37 Please read the MUSHclient FAQ - point 37.


... for how you might detect an inventory, without using a multi-line trigger.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] 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
[Go to top] 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,098 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]