View Single Post
05/05/14, 02:32 AM   #4
SpecialK
Join Date: Apr 2014
Posts: 6
A handy way for formatted print to screen with a default color; sort of C "printf()" style.

Lua Code:
  1. local function p(...)
  2.    local function w(...) CHAT_SYSTEM:AddMessage("|cD8C1FF"..string.format(...).."|r") end
  3.    local s, r = pcall(w, ...)
  4.    if not s then error(r, 2) end
  5. 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:
  1. 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.
  Reply With Quote