Help with Lua: Detecting First Instance of Colored Text

Posted by Aeagle on Sat 09 Mar 2024 04:19 PM — 3 posts, 7,606 views.

#0
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
Amended on Sat 09 Mar 2024 04:20 PM by Aeagle
Australia Forum Administrator #1
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.
Australia Forum Administrator #2
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.