Quantcast
WoWInterface - View Single Post - setText or setFormattedText or ?
View Single Post
10-03-16, 11:19 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, the TEXT() function is legacy code from the very earliest iterations of the Blizzard UI; you should never use it in an addon. It literally just returns the string you pass to it:

Code:
    function TEXT(text)
      return text;
    end
Just write the string you want to use.

As to the actual question:

SetText and SetFormattedText are methods that exist on font string objects -- not string values. "Font string" is a type of widget in the WoW UI API, like "texture", "frame", or "button". "String" is a type of value in the Lua programming language, like "number", "boolean", or "table".

If you want to display text, you either need to create a font string (which in turn needs to be attached to a frame):

lua Code:
  1. local frame = CreateFrame("Frame", "LazareQuestFrame", UIParent)
  2. frame:SetSize(100, 100)
  3. frame:SetPoint("CENTER")
  4.  
  5. local fontstring = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  6. fontstring:SetPoint("CENTER")

... or find the name of, or a reference to, a font string that already exists in the UI. Then you can tell it what text to display:

Lua Code:
  1. fontstring:SetText("Track")

SetFormattedText is a "shortcut" to calling string.format and SetText; these do the same thing:

Lua Code:
  1. fontstring:SetText(string.format("You have %d cats.", 42))
  2. fontstring:SetFormattedText("You have %d cats.", 42)

The difference is that SetFormattedText shifts the string.format operation over into C code, where it's (presumably) faster than running it in Lua. Unless you're doing it a million times in a row, though, you'll never notice the difference, so the main reason to use SetFormattedText is that it makes your code less verbose and more readable.

Edit:
After re-reading your post I noticed that you mentioned you think the TRACK_QUEST_ABBREV variable is referring a button. That is not correct -- the Blizzard UI code defines TRACK_QUEST_ABBREV as containing the string "Track". If you overwrote that value with a pointer to a button object, that's even worse -- not only does your code still not work, but you're also breaking any part of the default UI and other addons that expect TRACK_QUEST_ABBREV to be a string.

Please post the rest of your code.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 10-03-16 at 11:25 PM.
  Reply With Quote