Hide player status text (HP/mana) unless moused over

I’ve been using a very small addon for a while that enables the target unit frame to display status text (health and resources) while keeping the status text hidden on the player unit frame UNLESS you mouse over it in which case the text shows temporarily.

It has broken in 10.0.2. Here’s the addon code:

local function alphaText(self,alpha)
  local stub = (self:GetName() or ""):match("(.-Frame)")
  if stub then
    _G[stub.."HealthBar"].TextString:SetAlpha(alpha)
    _G[stub.."ManaBar"].TextString:SetAlpha(alpha)
  end
end
local function showText(self)
  alphaText(self,1)
end
local function hideText(self)
  alphaText(self,0)
end
local function hookFrame(frameName)
  _G[frameName]:HookScript("OnEnter",showText)
  _G[frameName]:HookScript("OnLeave",hideText)
  _G[frameName.."HealthBar"]:HookScript("OnEnter",showText)
  _G[frameName.."HealthBar"]:HookScript("OnLeave",hideText)
  _G[frameName.."ManaBar"]:HookScript("OnEnter",showText)
  _G[frameName.."ManaBar"]:HookScript("OnLeave",hideText)
  hideText(_G[frameName])
end
hookFrame("PlayerFrame")
hookFrame("PetFrame")

And here’s the error it’s throwing now:

8x Interface/AddOns/TargetHP/TargetHP.lua:18: attempt to index field '?' (a nil value)
[string "@Interface/AddOns/TargetHP/TargetHP.lua"]:18: in function `hookFrame'
[string "@Interface/AddOns/TargetHP/TargetHP.lua"]:26: in main chunk

Locals:
frameName = "FocusFrame"
(*temporary) = nil
(*temporary) = nil
(*temporary) = "HealthBar"
(*temporary) = <function> defined @Interface/AddOns/TargetHP/TargetHP.lua:12
(*temporary) = "attempt to index field '?' (a nil value)"
showText = <function> defined @Interface/AddOns/TargetHP/TargetHP.lua:9
hideText = <function> defined @Interface/AddOns/TargetHP/TargetHP.lua:12

I can’t figure out why the error references “FocusFrame” since that is literally nowhere in the lua code. I don’t care about the focus frame. Any thoughts?

Try this

local function showText(self)
    self.TextString:SetAlpha(1)
end
local function hideText(self)
    self.TextString:SetAlpha(0)
end
local function hookFrame(frame)
    frame:HookScript("OnEnter",showText)
    frame:HookScript("OnLeave",hideText)
    hideText(frame)
end
hookFrame(PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.HealthBarArea.HealthBar)
hookFrame(PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.ManaBarArea.ManaBar)
hookFrame(PetFrameHealthBar)
hookFrame(PetFrameManaBar)

edit: The above shows only the text of the statusbar you mouseover. The following is an alternate one that shows both health/mana when you mouseover the player or pet frame (most of it, anyway)

local textStrings = {
  player = {
    PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.HealthBarArea.HealthBar.TextString,
    PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.ManaBarArea.ManaBar.TextString
  },
  pet = {
    PetFrameHealthBar.TextString,
    PetFrameManaBar.TextString
  }
}

local function alphaText(which,alpha)
  for _,fontstring in ipairs(textStrings[which]) do
    fontstring:SetAlpha(alpha)
  end
end
local function showText(which)
  alphaText(which,1)
end
local function hideText(which)
  alphaText(which,0)
end
local function hookFrame(which,frame)
  frame:HookScript("OnEnter",function(self) showText(which) end)
  frame:HookScript("OnLeave",function(self) hideText(which) end)
  hideText(which)
end
hookFrame("player",PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.HealthBarArea.HealthBar)
hookFrame("player",PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.ManaBarArea.ManaBar)
hookFrame("player",PlayerFrame)
hookFrame("pet",PetFrameHealthBar)
hookFrame("pet",PetFrameManaBar)
hookFrame("pet",PetFrame)

You, sir, are the man. Works perfectly. :smiley: Thanks!

I like that this addon totally hides text on the player frame, but I also want to shorten the text on the other frames so that they only show remaining health and mana: 819k / 819k for health → 819k, and 250k / 250k for mana → 250k . I know this is an old thread, but any help would be appreciated.