View Single Post
01-30-23, 09:20 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I had a semicolon in a bad spot. I ended up rewriting the code to use OnUpdate because each UnitFrame has a lot of children that made the OnEnter/OnLeave scripts fire erratically.

Lua Code:
  1. --  Configuration
  2. local ShowAlpha=1;
  3. local HideAlpha=0.05;
  4.  
  5. --  Visibility logic
  6. local function UnitFrame_UpdateVisibility(self)
  7.     self:SetAlpha(
  8.         (
  9.             InCombatLockdown()--    Check combat
  10.         or  UnitIsUnit("target","player")-- Check targeting self
  11.         or  self:IsMouseOver()--    Check mouseover
  12.         ) and ShowAlpha or HideAlpha
  13.     );
  14. end
  15.  
  16. PlayerFrame:HookScript("OnUpdate",UnitFrame_UpdateVisibility);
  17. TargetFrame:HookScript("OnUpdate",UnitFrame_UpdateVisibility);


For future reference, script errors are turned off by default. You can enable them by typing this command into chat.
Code:
/console scriptErrors 1
Also local limits the visibility of a function/variable to a specific blocks of code referred to as its "scope". This is in contrast to "globals", which can be accessed by anyone. It's recommended to use locals whenever possible to prevent accidental overwriting of another code's variables or the same happening to yours.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-01-23 at 08:33 PM. Reason: removed excess end parenthesis from :SetAlpha() call
  Reply With Quote