A handy way for formatted print to screen with a default color; sort of C "printf()" style.
Lua Code:
local function p(...)
local function w(...) CHAT_SYSTEM:AddMessage("|cD8C1FF"..string.format(...).."|r") end
local s, r = pcall(w, ...)
if not s then error(r, 2) end
end
With the
pcall() to the wrapper it will catch
string.format() errors and point to the exact "p()" call where it happened (like accidentally passing a "nil" value for example). With out this setup it you'll only see the context on/inside the "p()" call it's self.
Example usage:
Lua Code:
p("My name is \"%s\"", GetUnitName("player"))
You could add more variations of course.
Like pass a color argument instead of a default color "local function p(color, ...)", etc.