Go to Page... |
Thread Tools | Display Modes |
07-02-12, 03:04 PM | #1 |
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> } This is the relavant section of code: LUA Code:
And here is the entire code: LUA Code:
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.. |
|
07-02-12, 03:24 PM | #2 |
VARIABLES_LOADED is a useless event, and is causing this problem. It fires many times during the loading process to indicate that various Blizzard or game settings are loading, and has nothing to do with addons. At that time, information about your character's experience is not yet available. Just remove that event entirely. You don't need it. You're already catching the "I'm logged in, info is now available" event with PLAYER_LOGIN, PLAYER_ENTERING_WORLD, and PLAYER_XP_UPDATE.
__________________
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. Last edited by Phanx : 07-02-12 at 03:27 PM. |
|
07-02-12, 04:16 PM | #3 |
Phanx... I love you! Thanks so much, it's working perfectly in the beta for now. A little more testing and I'll upload it to the beta section.
|
|
07-03-12, 07:27 AM | #4 |
Last night while messing around in Beta, I decided I wanted to add some additional texture options to my xp bar. I found the ones I wanted, sized them made them work and made them user selected via slash command. Now I'm stuck on how to get them to save per character. I tried it the same way that I did it for locked/unlocked visable/hidden and couldn't get it to work. I'm guessing it's because I'm not defining the variable correctly, but for the life of me I can't figure out a way to define the variable and save it. Hopefully one of you guys will see something that I don't.
Here's my code: LUA Code:
Here's my TOC: LUA Code:
and attached is the full addon just in case. |
|
07-03-12, 03:38 PM | #5 |
You need to do a check like this:
lua Code:
This uses the pre-existing SVs or creates an empty table if there are none. You can also improve your slashcmdhandler like this: lua Code:
This works by doing a simple table lookup and quickly coming back with a result or nil, instead of testing each check in an if-else chain.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Author of NPCScan and many other AddOns. |
|
07-03-12, 05:06 PM | #6 |
Thanks Torhal. So more or less then I need to define the saved variable like this
Code:
TXPTexture = TXPTexture or {} Code:
TXPTexture = TribalExperienceBar:SetStatusBarTexture("..") |
|
07-03-12, 07:26 PM | #7 |
Change your TOC so it actually saves the variable:
Code:
## SavedVariablesPerCharacter: TXPVisible, TXPLocked, TXPTexture Code:
curve = function() if TXPTexture == "curve" then TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") print("Texture already set to Curve") else TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") TXPTexture = "curve" print("Texture set to Curve") end end, On a side note, if you are performing a boolean check, eg. doing one thing if X == true and another thing if Y == false, the most efficient way to do that is like this: Code:
if X then DoSomething() else DoSomethingElse() end Code:
if X == true then DoSomething() elseif X == false then DoSomethingElse() end
__________________
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. |
|
07-03-12, 08:05 PM | #8 |
Thanks Phanx. Now i have one more small(ish) problem.
I changed my TOC to: Code:
## Interface: 40300 ## Title: Tribal XP Bar ## Notes: Tribally XP Bar of Prettiness ## Author: Othgar ## Version: 1.0b ## SavedVariablesPerCharacter: TXPVisible, TXPLocked, TXPTexture TXP.lua Code:
-- Tribal Experience Bar -- By: Othgar -- Copyleft All Rights Reversed -- Default state TXPVisible = true; TXPLocked = true; -- Constants local ThousandSeparator = "," local TipTitle = "Tribal XP" local _, class = UnitClass("player") local r,g,b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b local function FmtBigNum(n) local left, num, right = string.match(n .. "", '^([^%d]*%d)(%d*)(.-)') return left..(num:reverse():gsub('(%d%d%d)', '%1'.. ","):reverse())..right end local TribalExperienceBar = CreateFrame("StatusBar","TribalExperienceBar",UIParent) TribalExperienceBar:SetSize(675, 150) TribalExperienceBar:SetPoint("CENTER", UIParent, "CENTER", 0, 0); TribalExperienceBar:SetFrameStrata("MEDIUM"); TribalExperienceBar:SetClampedToScreen(1); TribalExperienceBar:SetBackdrop({bgFile="Interface\\Tooltips\\UI-Tooltip-Background", edgeFile="", tile=1, tileSize=10, edgeSize=10, insets={left=2, right=2, top=2, bottom=2}}); TribalExperienceBar:SetBackdropColor(r,g,b,0) TribalExperienceBar:SetMovable(1); TribalExperienceBar:EnableMouse(1); TribalExperienceBar:SetStatusBarTexture("TXPTexture") TribalExperienceBar:SetStatusBarColor(r,g,b) TribalExperienceBar:SetAlpha(.75) local TXPBarText = TribalExperienceBar:CreateFontString("TXPBarText","OVERLAY"); TXPBarText:SetFontObject(GameFontNormal) TXPBarText:SetTextColor(r,g,b) TXPBarText:SetPoint("CENTER", TribalExperienceBar, "BOTTOM", 0, 0); TXPBarText:SetJustifyH("CENTER"); TXPBarText:SetJustifyV("CENTER"); --Register Events TribalExperienceBar:RegisterEvent("PLAYER_ENTERING_WORLD"); TribalExperienceBar:RegisterEvent("PLAYER_XP_UPDATE"); TribalExperienceBar:RegisterEvent("PLAYER_LOGIN"); TribalExperienceBar:RegisterEvent("PLAYER_LEVEL_UP"); --Event handling TribalExperienceBar:SetScript("OnEvent", function(self, event, ...) local curxp = UnitXP("player") local levelmax = UnitXPMax("player") local perc = string.format("%.1f%%", (100*(curxp/levelmax))) local perbox = levelmax / 20 local mystr = string.format("%.1fb - %.1fb tnl | %s", curxp / perbox, (levelmax - curxp) / perbox, perc) TXPBarText:SetText(mystr) TribalExperienceBar:SetMinMaxValues(0, levelmax) TribalExperienceBar:SetValue(curxp) if TXPVisible then TribalExperienceBar:Show() else TribalExperienceBar:Hide() end end) -- move me TribalExperienceBar:SetScript("OnMouseDown", function() if not TXPLocked then TribalExperienceBar:StartMoving() else TribalExperienceBar:StopMovingOrSizing() end end) TribalExperienceBar:SetScript("OnMouseUp", function() TribalExperienceBar:StopMovingOrSizing() end) -- register slash commands SLASH_TXP1 = '/TXP'; local COMMAND_PARAMS = { hide = function() if TXPVisible then TXPVisible=false TribalExperienceBar:Hide() print("Experience hidden, type /TXP show to show.") end end, show = function() if not TXPVisible then TXPVisible=true TribalExperienceBar:Show() print("Experience displayed, type /TXP hide to hide.") end end, rested = function() if GetXPExhaustion() == nil then print("You have no rested EXP.") else print("You have "..GetXPExhaustion().." rested EXP remaining.") end end, lock = function() if TXPLocked == true then TXPLocked = false print("TXP UNlocked") elseif TXPLocked == false then TXPLocked = true print("TXP Locked") end end, curve = function() if TXPTexture == "curve" then TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") print("Texture already set to Curve") else TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") TXPTexture = "curve" print("Texture set to Curve") end end, simple = function() if TXPTexture == "simple" then TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple") print("Texture already set to Simple") else TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple") TXPTexture = "simple" print("Texture set to Simple") end end, split = function() if TXPTexture == "split" then TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split") print("Texture already set to Split") else TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split") TXPTexture = "split" print("Texture set to Split") end end, } local function slashcmdhandler(param) if COMMAND_PARAMS[param] then COMMAND_PARAMS[param]() return end print("Valid commands are:"); print("/TXP show (Show the experience bar.)"); print("/TXP hide (Hide the experience bar.)"); print("/TXP rested (Shows the amount of rested XP.)"); print("/TXP Lock (Locks the experience bar if it is unlocked, Unlocks it if it is locked.") print("/TXP Curve (Sets the status bar texture to Curve.") print("/TXP Simple (Sets the bar texture to Simple") print("/TXP Split (Sets the Bar texture to Split") end SlashCmdList["TXP"] = slashcmdhandler; --Tooltip local function OnEnter(self) GameTooltip:Show() end local function OnLeave(self) GameTooltip:Hide() end --hide @ 85 if UnitLevel("player") >= 85 then TribalExperienceBar:Hide() print("Experience bar hidden, type /TXP show to show.") TXPVisible = false end Edit: After some more testing it seems that the texture remains set and appears after changing zones, but a /rl or logout requires me to reset the texture via slash command. Last edited by Othgar : 07-03-12 at 11:15 PM. Reason: update |
|
07-03-12, 11:38 PM | #9 |
Here - more fixups and streamlining. This separates the textures from the commands, removes duplicated code, and ensures that the param is of the same case (lower) as the table keys.
lua Code:
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Author of NPCScan and many other AddOns. Last edited by Torhal : 07-03-12 at 11:41 PM. |
|
07-04-12, 02:06 AM | #10 |
Sweet thanks Torhal! Working perfectly now on live, and I'll test it on beta tomorrow.
|
|
WoWInterface » Site Forums » Archived Beta Forums » MoP Beta archived threads » Updating TXP for MoP Beta |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|