So doing some fiddling, I think I've got some working code to compress the lines as desired:
--[[
Counts up the occurences of each unique line
Example Outputs:
[..3] Unique Line A
[.42] Unique Line B
[183] Unique Line C
]]
function aggregate_duplicates(text_stream)
local unique_text = {}
local unique_count = {}
for i, line in ipairs(text_stream) do
if unique_text[line] == nil then
unique_text[line] = line
unique_count[line] = 1
else
unique_count[line] = unique_count[line] + 1
end
end
for i, line in ipairs(unique_text) do
unique_text[i] = string.format("[.%03d] %s", unique_count[line], line)
end
return unique_text
end
Still trying to wrap my head around how to call this function. Do I place this in the "Scripts" section somewhere and call it in my trigger code section like below?
deleteLine()
substitution_lines = aggregate_duplicates(multimatches)
-- Make Pretty -> formatted_lines
cecho(formatted_lines)
What hurts my brain is trying to understand how and when I can make line substitutions, how much that hurts performance, and how do I make this extensible to other lists I might come across. Such as entering a dungeon area and there is a huge list of NPCs to sort through.
Thank you for the suggestions. They are helpful. I might be putting the chicken before the dinosaur by making the function first, but it was easier to start with something I can figure out easily.