1. #1

    Stripping text from tooltip scraping

    so I have this function:

    Code:
    local CostTip = CreateFrame('GameTooltip')
    local CostText = CostTip:CreateFontString()
    CostTip:AddFontStrings(CostTip:CreateFontString(), CostTip:CreateFontString())
    CostTip:AddFontStrings(CostText, CostTip:CreateFontString())
    -- the next function is what will be called to find the cost of a spell
    function GetPowerCost(spellId)
      -- returns the value of the second line of the tooltip
      -- bail if we don't have a spellId
      if spellId == nil then
        return nil
      else
        CostTip:SetOwner(WorldFrame, 'ANCHOR_NONE')
        CostTip:SetSpellByID(spellId)
        print(spellId .. ' = ' .. CostText:GetText())
        return CostText:GetText()
      end
    end
    but I'm unsure how to go about stripping the spell ID + power name from the return, for example I just want to be able to
    /dump GetPowerCost(53209)
    and get a return of:
    35

    right now I get:
    "35 Focus"

    thank you for any help

  2. #2
    Deleted
    Code:
    return string.match(CostText:GetText(), "%d+")
    would work with your example. But I didn't check how CostText is built (e.g. when multiple resources like DK runes are involved) so you may need to validate the string first.

    A hunter-only solution might look like
    Code:
    local cost = CostText:GetText()
    return string.find(cost, "^%d+ Focus$") and string.match(cost, "%d+")
    Last edited by mmoc7723fe36c9; 2015-07-07 at 09:40 AM.

  3. #3
    I'm the person who wrote that function, or at least the original version of it.

    If you go to that link, I had provided a method for converting the cost to a number.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •