Thread Tools Display Modes
11-10-14, 06:16 AM   #1
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Exp Bar issue update

Hey everyone i have a little problem with my exp bar code

It works fine but everytime it updates it creates a new frame

If someone can help me fix this i would be very happy!

Lua Code:
  1. local Experience = CreateFrame("Frame", nil, UIParent)
  2.  
  3. local function UpdateExp()
  4.  
  5.     local CurXP = UnitXP("player")
  6.     local XPMax = UnitXPMax("player")
  7.     local CurLvl = UnitLevel("player")
  8.     local RestXP = GetXPExhaustion()
  9.  
  10.     local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
  11.  
  12.     ExperienceBar:SetPoint('LEFT', oUF_AftermathhPlayer, -67, 52)
  13.     ExperienceBar:SetStatusBarTexture(AftermathhUI.media.texture)
  14.     ExperienceBar:SetSize(235, 18)
  15.     ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
  16.     ExperienceBar:SetBackdrop({
  17.         bgFile = AftermathhUI.media.blank,
  18.         insets = {top = -1, left = -1, bottom = -1, right = -1},
  19.     })
  20.     ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  21.  
  22.     CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
  23.  
  24.     ExperienceBar:EnableMouse()
  25.  
  26.     ExperienceBar:SetScript("OnEnter", function(self)
  27.         GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  28.         GameTooltip:AddLine("|cffffd200Experience|r")
  29.         GameTooltip:AddDoubleLine("Current EXP", CurXP, 1, 1, 1, 1, 1, 1)
  30.         GameTooltip:AddDoubleLine("Remaining EXP", XPMax - CurXP, 1, 1, 1, 1, 1, 1)
  31.        
  32.         if RestXP == nil then
  33.             GameTooltip:AddDoubleLine("Rested EXP", "0", 1, 1, 1, 1, 1, 1)
  34.         else
  35.             GameTooltip:AddDoubleLine("Rested EXP", RestXP, 1, 1, 1, 1, 1, 1)
  36.         end
  37.  
  38.         GameTooltip:Show()
  39.     end)
  40.    
  41.     ExperienceBar:SetScript("OnLeave", function()
  42.         if GameTooltip:IsShown() then
  43.         GameTooltip:Hide()
  44.         end
  45.     end)
  46.    
  47.     local Current, Max = UnitXP("player"), UnitXPMax("player")
  48.     local Rested = GetXPExhaustion()
  49.     local IsRested = GetRestState()
  50.    
  51.     ExperienceBar:SetMinMaxValues(0, Max)
  52.     ExperienceBar:SetValue(Current)
  53.  
  54.     if (IsRested == 1 and Rested) then
  55.         ExperienceBar:SetMinMaxValues(0, Max)
  56.         ExperienceBar:SetValue(Rested + Current)
  57.         ExperienceBar:SetStatusBarColor(0, 144/255, 1)
  58.     else
  59.         ExperienceBar:SetValue(0)
  60.     end
  61.  
  62.     local ExperienceFont = ExperienceBar:CreateFontString(nil, 'OVERLAY')
  63.     ExperienceFont:SetPoint('CENTER', ExperienceBar)
  64.     ExperienceFont:SetFont(AftermathhUI.media.font, 12, AftermathhUI.media.fontflag)
  65.     ExperienceFont:SetText(""..CurXP.." / "..XPMax.."")
  66.     if AftermathhUI.media.shadowoffset == true then
  67.         ExperienceFont:SetShadowOffset(1, -1)
  68.         ExperienceFont:SetShadowColor(0,0,0)
  69.     end
  70. end
  71.  
  72. Experience:RegisterEvent("PLAYER_XP_UPDATE")
  73. Experience:RegisterEvent("PLAYER_LEVEL_UP")
  74. Experience:RegisterEvent("UPDATE_EXHAUSTION")
  75. Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
  76. Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
  77.  
  78. Experience:SetScript("OnEvent", UpdateExp)
  Reply With Quote
11-10-14, 08:16 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Move line 10 outside and above local function UpdateExp(). That is where you are endlessly creating a new frame every time it updates.
  Reply With Quote
11-10-14, 09:25 AM   #3
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by myrroddin View Post
Move line 10 outside and above local function UpdateExp(). That is where you are endlessly creating a new frame every time it updates.
Thanks!
  Reply With Quote
11-10-14, 10:37 AM   #4
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
The bar value won't work or the rested exp font string.

the line 71 to 81 is that doesn't work.

Lua Code:
  1. ---- /////////////////////  EXP BAR ///////////// ----
  2.  
  3. local Experience = CreateFrame("Frame", nil, UIParent)
  4.  
  5. local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
  6.  
  7. local ExperienceBarRested = CreateFrame('StatusBar', nil, UIParent)
  8.  
  9. local InvisFrame = CreateFrame("Frame", nil, ExperienceBar)
  10. InvisFrame:SetFrameStrata("HIGH")
  11. InvisFrame:SetFrameLevel(5)
  12. InvisFrame:SetAllPoints()
  13.  
  14. local ExperienceFont = InvisFrame:CreateFontString(nil, 'OVERLAY') 
  15.  
  16. local Current, Max = UnitXP("player"), UnitXPMax("player")
  17. local CurLvl = UnitLevel("player")
  18. local Rested = GetXPExhaustion()
  19. local IsRested = GetRestState()
  20.  
  21. local function UpdateExp()
  22.  
  23.     ExperienceBar:SetPoint('LEFT', oUF_AftermathhPlayer, -67, 52)
  24.     ExperienceBar:SetStatusBarTexture(AftermathhUI.media.texture)
  25.     ExperienceBar:SetSize(235, 18)
  26.     ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
  27.     ExperienceBar:SetBackdrop({
  28.         bgFile = AftermathhUI.media.blank,
  29.         insets = {top = -1, left = -1, bottom = -1, right = -1},
  30.     })
  31.     ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  32.  
  33.     CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
  34.  
  35.     ExperienceBar:EnableMouse()
  36.    
  37.     ExperienceBar:SetScript("OnEnter", function(self)
  38.         GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  39.         GameTooltip:AddLine("|cffffd200Experience|r")
  40.         GameTooltip:AddDoubleLine("Current EXP", Current, 1, 1, 1, 1, 1, 1)
  41.         GameTooltip:AddDoubleLine("Remaining EXP", Max - Current, 1, 1, 1, 1, 1, 1)
  42.        
  43.         if Rested == nil then
  44.             GameTooltip:AddDoubleLine("Rested EXP", "0", 1, 1, 1, 1, 1, 1)
  45.         else
  46.             GameTooltip:AddDoubleLine("Rested EXP", Rested, 1, 1, 1, 1, 1, 1)
  47.         end
  48.  
  49.         GameTooltip:Show()
  50.     end)
  51.    
  52.     ExperienceBar:SetScript("OnLeave", function()
  53.         if GameTooltip:IsShown() then
  54.         GameTooltip:Hide()
  55.         end
  56.     end)
  57.    
  58.     ExperienceBarRested:SetSize(230, 18)
  59.     ExperienceBarRested:SetAlpha(0.5)
  60.     ExperienceBarRested:SetParent(ExperienceBar)
  61.     ExperienceBarRested:SetAllPoints(ExperienceBar)
  62.     ExperienceBarRested:SetStatusBarTexture(AftermathhUI.media.texture)
  63.     ExperienceBarRested:SetStatusBarColor(0, 144/255, 1)
  64.  
  65.     ExperienceFont:SetFont(AftermathhUI.media.font, 12, AftermathhUI.media.fontflag)   
  66.     if AftermathhUI.media.shadowoffset == true then
  67.         ExperienceFont:SetShadowOffset(1, -1)
  68.         ExperienceFont:SetShadowColor(0,0,0)
  69.     end
  70.    
  71.     ExperienceBar:SetMinMaxValues(0, Max)
  72.     ExperienceBar:SetValue(Current)
  73.    
  74.     if (IsRested == 1 and Rested) then     
  75.         ExperienceBarRested:SetMinMaxValues(0, Max)
  76.         ExperienceBarRested:SetValue(Rested + Current)
  77.         ExperienceFont:SetText(""..Current.." / "..Max.."("..Rested..")")
  78.     else
  79.         ExperienceBar:SetValue(0)
  80.         ExperienceFont:SetText(""..Current.." / "..Max.."")
  81.     end
  82. end
  83.    
  84. Experience:RegisterEvent("PLAYER_XP_UPDATE")
  85. Experience:RegisterEvent("PLAYER_LEVEL_UP")
  86. Experience:RegisterEvent("UPDATE_EXHAUSTION")
  87. Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
  88. Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
  89.  
  90. Experience:SetScript("OnEvent", UpdateExp)
  Reply With Quote
11-10-14, 10:44 AM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
While I cant answer your question I recommend you clean up first
You're still creating new functions per update. Move all definitions out of your update function.
And only put stuff in there you need to update.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-10-14, 11:05 AM   #6
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Red face

Originally Posted by Rilgamon View Post
While I cant answer your question I recommend you clean up first
You're still creating new functions per update. Move all definitions out of your update function.
And only put stuff in there you need to update.
Okay, well the update still doesn't have any effect. I really can't figure why doh.


Lua Code:
  1. local Current, Max = UnitXP("player"), UnitXPMax("player")
  2. local CurLvl = UnitLevel("player")
  3. local Rested = GetXPExhaustion()
  4. local IsRested = GetRestState()
  5.  
  6. local Experience = CreateFrame("Frame", nil, UIParent)
  7.  
  8. local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
  9. local ExperienceBarRested = CreateFrame('StatusBar', nil, UIParent)
  10.  
  11. local InvisFrame = CreateFrame("Frame", nil, ExperienceBar)
  12. InvisFrame:SetFrameStrata("HIGH")
  13. InvisFrame:SetFrameLevel(5)
  14. InvisFrame:SetAllPoints()
  15.  
  16. local ExperienceFont = InvisFrame:CreateFontString(nil, 'OVERLAY') 
  17.  
  18. local function UpdateExp() 
  19.    
  20.     ExperienceBar:SetMinMaxValues(0, Max)
  21.     ExperienceBar:SetValue(Current)
  22.    
  23.     if (IsRested == 1 and Rested) then     
  24.         ExperienceBarRested:SetMinMaxValues(0, Max)
  25.         ExperienceBarRested:SetValue(Rested + Current)
  26.         ExperienceFont:SetText(""..Current.." / "..Max.."("..Rested..")")
  27.     else
  28.         ExperienceBar:SetValue(0)
  29.         ExperienceFont:SetText(""..Current.." / "..Max.."")
  30.     end
  31. end
  32.  
  33. ExperienceBar:SetPoint('LEFT', oUF_AftermathhPlayer, -25, 0)
  34. ExperienceBar:SetStatusBarTexture(AftermathhUI.media.texture)
  35. ExperienceBar:SetSize(235, 18)
  36. ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
  37. ExperienceBar:SetBackdrop({
  38.     bgFile = AftermathhUI.media.blank,
  39.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  40.     })
  41. ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  42.  
  43. CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
  44.  
  45. ExperienceBar:EnableMouse()
  46.    
  47. ExperienceBar:SetScript("OnEnter", function(self)
  48.     GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  49.     GameTooltip:AddLine("|cffffd200Experience|r")
  50.     GameTooltip:AddDoubleLine("Current EXP", Current, 1, 1, 1, 1, 1, 1)
  51.     GameTooltip:AddDoubleLine("Remaining EXP", Max - Current, 1, 1, 1, 1, 1, 1)
  52.        
  53.     if Rested == nil then
  54.         GameTooltip:AddDoubleLine("Rested EXP", "0", 1, 1, 1, 1, 1, 1)
  55.     else
  56.         GameTooltip:AddDoubleLine("Rested EXP", Rested, 1, 1, 1, 1, 1, 1)
  57.     end
  58.  
  59.     GameTooltip:Show()
  60. end)
  61.    
  62. ExperienceBar:SetScript("OnLeave", function()
  63.     if GameTooltip:IsShown() then
  64.     GameTooltip:Hide()
  65.     end
  66. end)
  67.    
  68. ExperienceBarRested:SetSize(230, 18)
  69. ExperienceBarRested:SetAlpha(0.5)
  70. ExperienceBarRested:SetParent(ExperienceBar)
  71. ExperienceBarRested:SetAllPoints(ExperienceBar)
  72. ExperienceBarRested:SetStatusBarTexture(AftermathhUI.media.texture)
  73. ExperienceBarRested:SetStatusBarColor(0, 144/255, 1)
  74.  
  75. ExperienceFont:SetFont(AftermathhUI.media.font, 12, AftermathhUI.media.fontflag)   
  76. if AftermathhUI.media.shadowoffset == true then
  77.     ExperienceFont:SetShadowOffset(1, -1)
  78.     ExperienceFont:SetShadowColor(0,0,0)
  79. end
  80.  
  81. Experience:RegisterEvent("PLAYER_XP_UPDATE")
  82. Experience:RegisterEvent("PLAYER_LEVEL_UP")
  83. Experience:RegisterEvent("UPDATE_EXHAUSTION")
  84. Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
  85. Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
  86.  
  87. Experience:SetScript("OnEvent", UpdateExp)
  Reply With Quote
11-10-14, 11:11 AM   #7
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Now move the actual query (Lines 1-4) into your update function.
Your values are only computed once now. You want the values queried everytime your update is triggered.
And make sure they're available, too for your OnEnter-Function.
__________________
The cataclysm broke the world ... and the pandas could not fix it!

Last edited by Rilgamon : 11-10-14 at 11:15 AM.
  Reply With Quote
11-10-14, 11:56 AM   #8
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by Rilgamon View Post
Now move the actual query (Lines 1-4) into your update function.
Your values are only computed once now. You want the values queried everytime your update is triggered.
And make sure they're available, too for your OnEnter-Function.
So like this?

Lua Code:
  1. ---- /////////////////////  EXP BAR ///////////// ----
  2.  
  3. local Current, Max = UnitXP("player"), UnitXPMax("player")
  4. local Rested = GetXPExhaustion()
  5. local IsRested = GetRestState()
  6.  
  7. local Experience = CreateFrame("Frame", nil, UIParent)
  8.  
  9. local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
  10. local ExperienceBarRested = CreateFrame('StatusBar', nil, UIParent)
  11.  
  12. local InvisFrame = CreateFrame("Frame", nil, ExperienceBar)
  13. InvisFrame:SetFrameStrata("HIGH")
  14. InvisFrame:SetFrameLevel(5)
  15. InvisFrame:SetAllPoints()
  16.  
  17. local ExperienceFont = InvisFrame:CreateFontString(nil, 'OVERLAY') 
  18.  
  19. local function UpdateExp()
  20.     local Current, Max = UnitXP("player"), UnitXPMax("player")
  21.     local Rested = GetXPExhaustion()
  22.     local IsRested = GetRestState()
  23.    
  24.     ExperienceBar:SetMinMaxValues(0, Max)
  25.     ExperienceBar:SetValue(Current)
  26.    
  27.     if (IsRested == 1 and Rested) then     
  28.         ExperienceBarRested:SetMinMaxValues(0, Max)
  29.         ExperienceBarRested:SetValue(Rested + Current)
  30.         ExperienceFont:SetText(""..Current.." / "..Max.."("..Rested..")")
  31.     else
  32.         ExperienceBar:SetValue(0)
  33.         ExperienceFont:SetText(""..Current.." / "..Max.."")
  34.     end
  35. end
  36.  
  37. ExperienceBar:SetPoint('LEFT', oUF_AftermathhPlayer, -25, 0)
  38. ExperienceBar:SetStatusBarTexture(AftermathhUI.media.texture)
  39. ExperienceBar:SetSize(235, 18)
  40. ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
  41. ExperienceBar:SetBackdrop({
  42.     bgFile = AftermathhUI.media.blank,
  43.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  44.     })
  45. ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  46.  
  47. CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
  48.  
  49. ExperienceBar:EnableMouse()
  50.    
  51. ExperienceBar:SetScript("OnEnter", function(self)
  52.     local Current, Max = UnitXP("player"), UnitXPMax("player")
  53.     local Rested = GetXPExhaustion()
  54.     local IsRested = GetRestState()
  55.    
  56.     GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  57.     GameTooltip:AddLine("|cffffd200Experience|r")
  58.     GameTooltip:AddDoubleLine("Current Exp", Current, 1, 1, 1, 1, 1, 1)
  59.     GameTooltip:AddDoubleLine("Remaining Exp", Max - Current, 1, 1, 1, 1, 1, 1)
  60.  
  61.     if Rested == nil then
  62.         GameTooltip:AddDoubleLine("Rested Exp", "0", 1, 1, 1, 1, 1, 1)
  63.     else
  64.         GameTooltip:AddDoubleLine("Rested Exp", Rested, 1, 1, 1, 1, 1, 1)
  65.     end
  66.  
  67.     GameTooltip:Show()
  68. end)
  69.    
  70. ExperienceBar:SetScript("OnLeave", function()
  71.     if GameTooltip:IsShown() then
  72.     GameTooltip:Hide()
  73.     end
  74. end)
  75.    
  76. ExperienceBarRested:SetSize(230, 18)
  77. ExperienceBarRested:SetAlpha(0.5)
  78. ExperienceBarRested:SetParent(ExperienceBar)
  79. ExperienceBarRested:SetAllPoints(ExperienceBar)
  80. ExperienceBarRested:SetStatusBarTexture(AftermathhUI.media.texture)
  81. ExperienceBarRested:SetStatusBarColor(0, 144/255, 1)
  82.  
  83. ExperienceFont:SetFont(AftermathhUI.media.font, 12, AftermathhUI.media.fontflag)   
  84. if AftermathhUI.media.shadowoffset == true then
  85.     ExperienceFont:SetShadowOffset(1, -1)
  86.     ExperienceFont:SetShadowColor(0,0,0)
  87. end
  88.  
  89. Experience:RegisterEvent("PLAYER_XP_UPDATE")
  90. Experience:RegisterEvent("PLAYER_LEVEL_UP")
  91. Experience:RegisterEvent("UPDATE_EXHAUSTION")
  92. Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
  93. Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
  94.  
  95. Experience:SetScript("OnEvent", UpdateExp)
  Reply With Quote
11-10-14, 11:57 AM   #9
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by Game92 View Post
So like this?
If it works we're done
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-10-14, 12:04 PM   #10
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by Rilgamon View Post
If it works we're done
Still doesn't work

I want the bar till fill untill you ding, and of course show how much exp that's left or how much that is rested.
  Reply With Quote
11-10-14, 12:22 PM   #11
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Works would be cleaver to set a point to the font string too haha! Through without with the rested exp bar.. Not sure what is the wrong in that.
  Reply With Quote
11-10-14, 12:27 PM   #12
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
I've changed it a little so it works without your UI and both bars show up like they should.

Lua Code:
  1. local Experience = CreateFrame("Frame", nil, UIParent)
  2.  
  3. local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
  4. local ExperienceBarRested = CreateFrame('StatusBar', nil, UIParent)
  5.  
  6. local InvisFrame = CreateFrame("Frame", nil, ExperienceBar)
  7. InvisFrame:SetFrameStrata("HIGH")
  8. InvisFrame:SetFrameLevel(5)
  9. InvisFrame:SetAllPoints()
  10.  
  11. local ExperienceFont = InvisFrame:CreateFontString(nil, 'OVERLAY')  
  12.  
  13. local function UpdateExp()
  14.     local Current, Max = UnitXP("player"), UnitXPMax("player")
  15.     local Rested = GetXPExhaustion()
  16.     local IsRested = GetRestState()
  17.    
  18.     ExperienceBar:SetMinMaxValues(0, Max)
  19.     ExperienceBar:SetValue(Current)
  20.    
  21.     if (IsRested == 1 and Rested) then      
  22.         ExperienceBarRested:SetMinMaxValues(0, Max)
  23.         ExperienceBarRested:SetValue(Rested + Current)
  24.         ExperienceFont:SetText(""..Current.." / "..Max.."("..Rested..")")
  25.     else
  26.         ExperienceBar:SetValue(0)
  27.         ExperienceFont:SetText(""..Current.." / "..Max.."")
  28.     end
  29. end
  30.  
  31. ExperienceBar:SetPoint('CENTER', UIParent,"CENTER")
  32. ExperienceBar:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  33. ExperienceBar:SetSize(235, 18)
  34. ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
  35. --[[ExperienceBar:SetBackdrop({
  36.     bgFile = AftermathhUI.media.blank,
  37.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  38.     })
  39. ]]--
  40. --ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  41.  
  42. --CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
  43.  
  44. ExperienceBar:EnableMouse()
  45.    
  46. ExperienceBarRested:SetSize(230, 18)
  47. ExperienceBarRested:SetAlpha(0.5)
  48. ExperienceBarRested:SetParent(ExperienceBar)
  49. ExperienceBarRested:SetAllPoints(ExperienceBar)
  50. ExperienceBarRested:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  51. ExperienceBarRested:SetStatusBarColor(0, 144/255, 1)
  52.  
  53. ExperienceFont:SetFont("Fonts\\FRIZQT__.TTF", 12)    
  54.  
  55.  
  56. Experience:RegisterEvent("PLAYER_XP_UPDATE")
  57. Experience:RegisterEvent("PLAYER_LEVEL_UP")
  58. Experience:RegisterEvent("UPDATE_EXHAUSTION")
  59. Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
  60. Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
  61.  
  62. Experience:SetScript("OnEvent", UpdateExp)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-10-14, 01:30 PM   #13
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by Rilgamon View Post
I've changed it a little so it works without your UI and both bars show up like they should.

Lua Code:
  1. local Experience = CreateFrame("Frame", nil, UIParent)
  2.  
  3. local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
  4. local ExperienceBarRested = CreateFrame('StatusBar', nil, UIParent)
  5.  
  6. local InvisFrame = CreateFrame("Frame", nil, ExperienceBar)
  7. InvisFrame:SetFrameStrata("HIGH")
  8. InvisFrame:SetFrameLevel(5)
  9. InvisFrame:SetAllPoints()
  10.  
  11. local ExperienceFont = InvisFrame:CreateFontString(nil, 'OVERLAY')  
  12.  
  13. local function UpdateExp()
  14.     local Current, Max = UnitXP("player"), UnitXPMax("player")
  15.     local Rested = GetXPExhaustion()
  16.     local IsRested = GetRestState()
  17.    
  18.     ExperienceBar:SetMinMaxValues(0, Max)
  19.     ExperienceBar:SetValue(Current)
  20.    
  21.     if (IsRested == 1 and Rested) then      
  22.         ExperienceBarRested:SetMinMaxValues(0, Max)
  23.         ExperienceBarRested:SetValue(Rested + Current)
  24.         ExperienceFont:SetText(""..Current.." / "..Max.."("..Rested..")")
  25.     else
  26.         ExperienceBar:SetValue(0)
  27.         ExperienceFont:SetText(""..Current.." / "..Max.."")
  28.     end
  29. end
  30.  
  31. ExperienceBar:SetPoint('CENTER', UIParent,"CENTER")
  32. ExperienceBar:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  33. ExperienceBar:SetSize(235, 18)
  34. ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
  35. --[[ExperienceBar:SetBackdrop({
  36.     bgFile = AftermathhUI.media.blank,
  37.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  38.     })
  39. ]]--
  40. --ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  41.  
  42. --CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
  43.  
  44. ExperienceBar:EnableMouse()
  45.    
  46. ExperienceBarRested:SetSize(230, 18)
  47. ExperienceBarRested:SetAlpha(0.5)
  48. ExperienceBarRested:SetParent(ExperienceBar)
  49. ExperienceBarRested:SetAllPoints(ExperienceBar)
  50. ExperienceBarRested:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  51. ExperienceBarRested:SetStatusBarColor(0, 144/255, 1)
  52.  
  53. ExperienceFont:SetFont("Fonts\\FRIZQT__.TTF", 12)    
  54.  
  55.  
  56. Experience:RegisterEvent("PLAYER_XP_UPDATE")
  57. Experience:RegisterEvent("PLAYER_LEVEL_UP")
  58. Experience:RegisterEvent("UPDATE_EXHAUSTION")
  59. Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
  60. Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
  61.  
  62. Experience:SetScript("OnEvent", UpdateExp)
Thanks for help! Works now!
  Reply With Quote
11-10-14, 04:27 PM   #14
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Just so you know, you do not need to explicitly need to check for true, false, or nil in Lua. For readability, these are the same.
Code:
-- the value is true
if a == true then ...
if a ~= false then ...
if a ~= nil then ...
if a then ... <-- use this!

-- the value is false or nil
if a == false then ...
if a == nil then ...
if a ~= true then ...
if not a then ... <-- use this!
Only explicitly check if the value of a can be tri-state, like true/false/nil or 1/0/nil.
  Reply With Quote
11-10-14, 05:13 PM   #15
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by myrroddin View Post
Just so you know, you do not need to explicitly need to check for true, false, or nil in Lua. For readability, these are the same.
Code:
-- the value is true
if a == true then ...
if a ~= false then ...
if a ~= nil then ...
if a then ... <-- use this!

-- the value is false or nil
if a == false then ...
if a == nil then ...
if a ~= true then ...
if not a then ... <-- use this!
Only explicitly check if the value of a can be tri-state, like true/false/nil or 1/0/nil.
Oh okay! Didn't know actually! Thanks
  Reply With Quote
11-10-14, 05:59 PM   #16
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by myrroddin View Post
Just so you know, you do not need to explicitly need to check for true, false, or nil in Lua. For readability, these are the same.
Code:
-- the value is true
if a == true then ...
if a ~= false then ...
if a ~= nil then ...
if a then ... <-- use this!

-- the value is false or nil
if a == false then ...
if a == nil then ...
if a ~= true then ...
if not a then ... <-- use this!
Only explicitly check if the value of a can be tri-state, like true/false/nil or 1/0/nil.
HA! I didn't know this either; thanks! (Or rather I have the bad habit of doing the true/false check)
__________________
  Reply With Quote
11-10-14, 07:04 PM   #17
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I should point out that checking for 1/nil does not work as per above. If you do find a 1/nil, you will have to check, but there are a few ways.
Code:
-- if value == 1
if a == 1 then ... <-- use this!
if not a == nil then ... (it isn't nil, but it might not be 1 either)
if a ~= nil then ... (it isn't nil, but it might not be 1 either)
if a then ... <-- will NOT work! Lua will expect a == true, when a's value is actually 1 (1 =/= true, obviously)

-- if value == nil
if a == nil then ...
if not a then ... <-- use this!
if not a == 1 then ... (it isn't 1, but it might not be nil, could be "cats" or 327)
if a ~= 1 then ... (it isn't 1, but it might not be nil, could be "cats" or 327)
Except for tri-state variables, the not operator in Lua defaults to either false or nil, as appropriate.
  Reply With Quote
11-10-14, 08:34 PM   #18
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by myrroddin View Post
I should point out that checking for 1/nil does not work as per above. If you do find a 1/nil, you will have to check, but there are a few ways.
That's not actually the case. Lua's if statement works with any value, not just booleans. nil and false are false-equivalent, all other values are true-equivalent. if a then will still work as expected if a is 1/nil instead of true/false.

Last edited by Choonstertwo : 11-10-14 at 08:40 PM.
  Reply With Quote
11-10-14, 10:40 PM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
I should point out that checking for 1/nil does not work as per above. If you do find a 1/nil, you will have to check, but there are a few ways.
No. A simple "if var then" check will pass if the value of var is anything other than false or nil. It doesn't matter if it's true, 9000, a string, a table, a function, etc.
__________________
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
11-10-14, 11:46 PM   #20
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I was thinking about 1/0 when I wrote that. Oops me.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Exp Bar issue update

Thread Tools
Display Modes

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