Appending to the end of a line - Solution

Posted by Kathan on Sun 27 Jul 2014 06:30 PM — 2 posts, 11,980 views.

USA #0
This is a simple script for appending text to the end of a mud output line while keeping the original colors of original line.

I'm posting this in the hopes that it will help someone else at some point. I spent quite a while looking for a forum topic on appending text to lines in the output window before I stumbled onto some posts about style runs. Once I found out style runs, I was able to find more posts describing what I wanted, but none using the keywords I was looking for.

This snippet can go in the body of any trigger.
Make sure that the trigger is set to send to 14 (Script after Omit), otherwise TriggerStyleRuns won't be available and the script will break.


for k, _ in ipairs(TriggerStyleRuns) do

   test = TriggerStyleRuns[k]

   ColourTell ( RGBColourToName(test.textcolour), RGBColourToName(test.backcolour), test.text)

end --for

ColourNote ("red", "", " Appended!" )


This code could be as easily modified to prepend by placing the ColourNote before the for loop.

I have to give credit to the following threads for helping me figure out my problem.

Template:post=7818
Please see the forum thread: http://gammon.com.au/forum/?id=7818.

Template:post=12464
Please see the forum thread: http://gammon.com.au/forum/?id=12464.
Amended on Sun 27 Jul 2014 06:32 PM by Kathan
Australia Forum Administrator #1
You are calling TriggerStyleRuns twice which is not necessary. This is simpler:


for k, v in ipairs(TriggerStyleRuns) do
   ColourTell ( RGBColourToName(v.textcolour), 
                RGBColourToName(v.backcolour), 
                v.text)
end --for

ColourNote ("red", "", " Appended!" )