Nick Gammon said:
Quote:
1) What's with the unnecessary indent?
The indent is because you don't get rid of the space after the spoof stuff. If you tprint the style runs you see this:
1:
"textcolour"=8454143
"backcolour"=0
"length"=34
"style"=0
"text"="[Barrabus(#9443){Shawn}<-(#10322)]"
2:
"textcolour"=12632256
"backcolour"=0
"length"=249
"style"=0
"text"=" As you enter, Barrabus lifts a hand in greeting. "Welcome t' th' Fighters Guild! If yer new here, I c'n answer some questions! (OOC: Information is available via '+fg/info'. '+fg/help' will give you help on commands that work on the Guild grounds)."
Notice the space at the start of style #2?
Yes. I should have realized that was what was happening, damn.
Also, I was trying several ways yesterday to print the styles table so I could get a better idea of what was going on. Tried searching the site for a "tables" display. Didn't find tprint, it feels so obvious in retrospect, to see if there was a t-something.
Nick Gammon said:
One approach would be to omit a leading space at the start of the second style, if you know it is style #2, like this:
for k,v in ipairs(styles) do
text = string.gsub(v.text, noSpoof, "")
if k == 2 then
text = string.gsub (text, "^ ", "")
end -- leading space on first style run
ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
end
If it isn't always style #2 you might have to have a flag which checks if you have output anything yet, and if not trim the first space, eg.
function pnp.nospoof.gather(name, line, wildcards, styles)
--print(wildcards[1])
local noSpoof = string.gsub(wildcards[1], "[%^%$%(%)%%%.%{%}%[%]%*%+%-%?]", "%%%1")
noSpoof = string.gsub(noSpoof, "^%s", "")
local outputted = false
for k,v in ipairs(styles) do
text = string.gsub(v.text, noSpoof, "")
if not outputted then
text = string.gsub (text, "^ ", "")
end -- leading space on first output
if #text > 0 then
outputted = true
end -- if
ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
end
Note()
end
This code
noSpoof = string.gsub(noSpoof, "^%s", "")
Was intended to get rid of the space. I assume it didn't work since the line was not yet split. Which simply indicates that I need to understand how style runs work better first.
Question...
If the first gsub isn't clearing out the nospoof stuff, what IS it doing? |