View Single Post
07-02-12, 03:04 PM   #1
Othgar
"That" Guy
 
Othgar's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 228
Updating TXP for MoP Beta

I just finally got a chance to login and start working on my experience bar addon today and after fighting with getting DC'd at 90% loaded for a few hours I got this error:
Code:
Message: Interface\AddOns\TXP\TXP.lua:58: Division by zero
Time: 07/02/12 16:28:24
Count: 1
Stack: Interface\AddOns\TXP\TXP.lua:58: in function <Interface\AddOns\TXP\TXP.lua:55>

Locals: self = TribalExperienceBar {
 0 = <userdata>
}
event = "VARIABLES_LOADED"
curxp = 0
levelmax = 0
(*temporary) = <function> defined =[C]:-1
(*temporary) = "%.1f%%"
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "Division by zero"
TXPBarText = TXPBarText {
 0 = <userdata>
}
TribalExperienceBar = TribalExperienceBar {
 0 = <userdata>
}
It looks to me like curxp/levelmax is returning 0 and breaking the addon. "Division by Zero" and all that. I can't find any changes in the API anywhere that would do this though (although this is my first update for an expansion I could be missing a million things lol).

This is the relavant section of code:
LUA Code:
  1. TribalExperienceBar:SetScript("OnEvent", function(self, event, ...)
  2.     local curxp = UnitXP("player")
  3.     local levelmax = UnitXPMax("player")
  4.     local perc = string.format("%.1f%%", (100*(curxp/levelmax)))
  5.     local perbox = levelmax / 20
  6.  
  7.     local mystr = string.format("%.1fb - %.1fb tnl | %s",  curxp / perbox, (levelmax - curxp) / perbox, perc)
  8.    
  9.     TXPBarText:SetText(mystr)
  10.     TribalExperienceBar:SetWidth(675)
  11.     TribalExperienceBar:SetHeight(150)
  12.    
  13.     TribalExperienceBar:SetMinMaxValues(0, levelmax)
  14.     TribalExperienceBar:SetValue(curxp)
  15.  
  16.     if TXPVisible then
  17.         TribalExperienceBar:Show()
  18.     else
  19.         TribalExperienceBar:Hide()
  20.     end
  21. end)

And here is the entire code:
LUA Code:
  1. -- Tribal Experience Bar
  2. -- By: Othgar
  3. -- Copyleft All Rights Reversed
  4.  
  5. -- Default state
  6. TXPVisible = true;
  7. TXPLocked = true;
  8.  
  9. -- Constants
  10. local ThousandSeparator = ","
  11. local TipTitle = "Tribal XP"
  12. local _, class = UnitClass("player")
  13. local r,g,b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
  14.  
  15.  
  16. local function FmtBigNum(n)
  17.         local left, num, right = string.match(n .. "", '^([^%d]*%d)(%d*)(.-)')
  18.         return left..(num:reverse():gsub('(%d%d%d)', '%1'.. ","):reverse())..right
  19. end
  20.  
  21. local TribalExperienceBar = CreateFrame("StatusBar","TribalExperienceBar",UIParent)
  22. TribalExperienceBar:SetWidth(95);
  23. TribalExperienceBar:SetHeight(50);
  24. TribalExperienceBar:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
  25. TribalExperienceBar:SetFrameStrata("MEDIUM");  
  26. TribalExperienceBar:SetClampedToScreen(1);
  27. TribalExperienceBar:SetBackdrop({bgFile="Interface\\Tooltips\\UI-Tooltip-Background", edgeFile="", tile=1, tileSize=10, edgeSize=10, insets={left=2, right=2, top=2, bottom=2}});
  28. TribalExperienceBar:SetBackdropColor(r,g,b,0)
  29. TribalExperienceBar:SetMovable(1);
  30. TribalExperienceBar:EnableMouse(1);
  31.  
  32. TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\xptexture_rentaire1")
  33. TribalExperienceBar:SetStatusBarColor(r,g,b)
  34. TribalExperienceBar:SetAlpha(.75)
  35.  
  36. local TXPBarText = TribalExperienceBar:CreateFontString("TXPBarText","OVERLAY");
  37. TXPBarText:SetFontObject(GameFontNormal)
  38. TXPBarText:SetTextColor(r,g,b)
  39. TXPBarText:SetPoint("CENTER", TribalExperienceBar, "BOTTOM", 30, 0);
  40. TXPBarText:SetJustifyH("CENTER");
  41. TXPBarText:SetJustifyV("CENTER");
  42.  
  43. local TribalExperienceBar1 = CreateFrame("Frame","TribalExperienceBar1",TribalExperienceBar)
  44. TribalExperienceBar1:SetPoint("TOPLEFT", TribalExperienceBar, "TOPLEFT", -2, 1);
  45. TribalExperienceBar1:SetPoint("BOTTOMRIGHT", TribalExperienceBar, "BOTTOMRIGHT", 2, -1);
  46.  
  47. TribalExperienceBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  48. TribalExperienceBar:RegisterEvent("VARIABLES_LOADED");
  49. TribalExperienceBar:RegisterEvent("PLAYER_XP_UPDATE");
  50. TribalExperienceBar:RegisterEvent("PLAYER_LOGIN");
  51. TribalExperienceBar:RegisterEvent("PLAYER_LEVEL_UP");  
  52.  
  53.  
  54. --Event handling
  55. TribalExperienceBar:SetScript("OnEvent", function(self, event, ...)
  56.     local curxp = UnitXP("player")
  57.     local levelmax = UnitXPMax("player")
  58.     local perc = string.format("%.1f%%", (100*(curxp/levelmax)))
  59.     local perbox = levelmax / 20
  60.  
  61.     local mystr = string.format("%.1fb - %.1fb tnl | %s",  curxp / perbox, (levelmax - curxp) / perbox, perc)
  62.    
  63.     TXPBarText:SetText(mystr)
  64.     TribalExperienceBar:SetWidth(675)
  65.     TribalExperienceBar:SetHeight(150)
  66.    
  67.     TribalExperienceBar:SetMinMaxValues(0, levelmax)
  68.     TribalExperienceBar:SetValue(curxp)
  69.  
  70.     if TXPVisible then
  71.         TribalExperienceBar:Show()
  72.     else
  73.         TribalExperienceBar:Hide()
  74.     end
  75. end)
  76.  
  77. -- move me
  78.  
  79. TribalExperienceBar:SetScript("OnMouseDown", function()
  80.     if not TXPLocked then
  81.         TribalExperienceBar:StartMoving()
  82.     else
  83.         TribalExperienceBar:StopMovingOrSizing()
  84.     end
  85. end)
  86.  
  87. TribalExperienceBar:SetScript("OnMouseUp", function() TribalExperienceBar:StopMovingOrSizing() end)
  88.  
  89.  
  90. -- register slash commands
  91.  
  92. SLASH_TXP1 = '/TXP';
  93. local function slashcmdhandler(param)
  94.     if param == "hide" then
  95.         if TXPVisible then
  96.             TXPVisible=false
  97.             TribalExperienceBar:Hide()
  98.             print("Experience hidden, type /TXP show to show.")
  99.         end
  100.     elseif param=="show" then
  101.         if not TXPVisible then
  102.             TXPVisible=true
  103.             TribalExperienceBar:Show()
  104.             print("Experience displayed, type /TXP hide to hide.")
  105.         end
  106.     elseif param=="rested" then
  107.         if GetXPExhaustion() == nil then
  108.             print("You have no rested EXP.")
  109.         else
  110.             print("You have "..GetXPExhaustion().." rested EXP remaining.")
  111.         end
  112.     elseif param == "lock" then
  113.         if TXPLocked == true then
  114.             TXPLocked = false
  115.             print("TXP UNlocked")
  116.         elseif TXPLocked == false then
  117.             TXPLocked = true
  118.            print("TXP Locked")
  119.         end
  120.  
  121.     else
  122.         print("Valid commands are:");
  123.         print("/TXP show (Show the experience bar.)");
  124.         print("/TXP hide (Hide the experience bar.)");
  125.         print("/TXP rested (Shows the amount of rested XP.)");
  126.         print("/TXP Lock (Locks the experience bar if it is unlocked, Unlocks it if it is locked.")
  127.     end
  128. end
  129. SlashCmdList["TXP"] = slashcmdhandler;
  130.  
  131. --Tooltip
  132.  
  133. local function OnEnter(self)  
  134.     GameTooltip:Show()
  135. end
  136.  
  137. local function OnLeave(self)  
  138.     GameTooltip:Hide()
  139. end
  140.  
  141. --hide @ 85
  142. if UnitLevel("player") >= 85 then
  143.     TribalExperienceBar:Hide() print("Experience bar hidden, type /TXP show to show.")
  144.     TXPVisible = false
  145. end

Any help would be awesom! Thanks guys!

Edit: Just realized I threw this in the wrong section... one of you wonderful admins want to stuff this in the corner where it belongs please.
__________________



Last edited by Othgar : 07-02-12 at 03:07 PM. Reason: Wrong section... derp..