While trying to answer a question about displaying a prompt with colours preserved, in this thread: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6589&page=999999, I've stumbled upon Lua's unpack() function, which solves a problem I've encountered a while ago, when trying to do essentially what the thread above asks. The problem was needing multiple ColourTell calls to display a prompt, which can be very bad for performance in some cases. Back then I opted for parsing packets in OnPluginPartialLine, which turned out to be much faster, but now I'd like to try to do it the "clean" way. There's a new problem however. Here's the function:
This looks like it should work, but every time I try to use it, I get an error complaining about a bad last argument to ColourNote (no value instead of string). The really confusing part is that if I add a print(unpack(args)) statement right before ColourNote(unpack(args)) then everything works just fine, except I get an extra note printed on the screen.
I've tried just unpacking the list prior to calling ColourNote, in hope that this is some quirk of unpack() that for some reason requires me to call it twice, so I can usefully employ the return from the second call, but with no luck - it seems to only work when I use print(unpack(args)).
Any ideas?
function echoLastPrompt()
prompt = table.remove(prompts)
-- if prompt is nil then we are out of prompts to
-- display for now
if prompt == nil then
return
end
local args = {} -- a table to hold ColourNote arguments
-- iterate over the styles in the prompt
for chunk,style in prompt do
table.insert(args, RGBColourToName(style.textcolour))
table.insert(args, RGBColourToName(style.backcolour))
table.insert(args, style.text)
end
ColourNote(unpack(args))
end
This looks like it should work, but every time I try to use it, I get an error complaining about a bad last argument to ColourNote (no value instead of string). The really confusing part is that if I add a print(unpack(args)) statement right before ColourNote(unpack(args)) then everything works just fine, except I get an extra note printed on the screen.
I've tried just unpacking the list prior to calling ColourNote, in hope that this is some quirk of unpack() that for some reason requires me to call it twice, so I can usefully employ the return from the second call, but with no luck - it seems to only work when I use print(unpack(args)).
Any ideas?