Thread Tools Display Modes
09-11-15, 11:18 AM   #1
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
formatting tooltip quest objective text

I'm currently grabbing the line of text displayed on the tooltip of a quest mob or item that tallies progress. — and I want to reformat the string returned slightly. This is the function i'm using to fetch the string:

Lua Code:
  1. local GetFormattedPVPOrObjectiveInfo = function()
  2.     local source = _G['GameTooltipTextLeft4']
  3.     local text = source:GetText()
  4.     if source and text ~= nil then
  5.         if text:find('^'..' - ') then     -- quest objective
  6.             return text
  7.         end
  8.     else return '' end
  9. end

i have a, uh, working knowledge of representative lua string symbols — and through a bit of dicking about discovered that changing line 6 to

Lua Code:
  1. return format('%s%s%s%s', 1, 1, 1, text)

will return



%s = 1
%s = 0
%s = .80
%s = - 0/6 rockjaw invader slain [the string i want]

is there a simple way to ditch the first 3 with gsub or some other string function, and then alter the 4th to remove the hyphen?
  Reply With Quote
09-11-15, 06:09 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Lua Code:
  1. return format('%s%s%s%s', 1, 1, 1, text)

I don't understand this. That's going to return something like "111text".
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-12-15, 02:56 AM   #3
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
oh noooooo

welp, i am an idiot — for some reason i thought the formatting was format(' ', r, ,g ,b, text) and I was pulling some mystery internal sequencing rather than the exact colour code i'd just written. friday night coding

well i guess that answers my question. thanks!

edit: just for posterity:

Lua Code:
  1. local GetFormattedPVPOrObjectiveInfo = function()
  2.     local source = _G["GameTooltipTextLeft4"]
  3.     local text = source:GetText()
  4.     if source and text ~= nil then
  5.         if text:find('^'..' - ') then                -- quest objective
  6.             text = text:gsub('-', '')            -- strip hyphen
  7.             text = text:gsub('^%s*', '')     -- strip leading whitespace
  8.             return text
  9.         end
  10.     else return '' end
  11. end

Last edited by ObbleYeah : 09-12-15 at 04:02 AM.
  Reply With Quote
09-16-15, 04:15 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You can condense this:

Code:
if text:find('^'..' - ') then                -- quest objective
            text = text:gsub('-', '')            -- strip hyphen
            text = text:gsub('^%s*', '')     -- strip leading whitespace
            return text
... to just this:

Code:
if text:find("^ - ") then -- why was there a concatenation operator in here?
            return text:sub(4)
Since your real goal is just to strip off the first 3 characters, just do that instead of beating around the bush with multiple gsub calls.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » formatting tooltip quest objective text


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off