-
Posted by Drunk Cadaver on Fri, 28 May 2010 22:31:59
I'm running into an issue with a mod I've written that makes no sense to me. I'm using OnMouseDown + Control to run some code in my XML document. Here is the code...
<OnMouseDown> testherald:SetScript("OnMouseDown", function() if IsShiftKeyDown() then this:StartMoving() end if IsControlKeyDown() then local th_time = GetWintergraspWaitTime() if th_time ~= nil then local th_sec = mod(th_time, 60) local th_min = mod(floor(th_time / 60), 60) local th_hour = floor(th_time / 3600) local th_remaining_time = th_hour .. ":" .. th_min .. ":" .. th_sec if th_min > 15 then SendChatMessage("Wintergrasp Time: " .. th_remaining_time,SAY) else SendChatMessage("Wintergrasp Time: " .. th_remaining_time .. " Queue available!",SAY) end else print("|cff6EB0DCHerald unable to announce time. The Battle is either in progress or you are in an instance or a Battleground.") end end end) </OnMouseDown> <OnMouseUp> testherald:SetScript("OnMouseUp", function() this:StopMovingOrSizing() end) </OnMouseUp>
The code works but I'd like to format the remaining time a little nicer. For example if the time is 1:9:5, I'd like it to output 1:09:05. I wrote the following code to do that...
<OnMouseDown> testherald:SetScript("OnMouseDown", function() if IsShiftKeyDown() then this:StartMoving() end if IsControlKeyDown() then local th_time = GetWintergraspWaitTime() if th_time ~= nil then local th_sec = mod(th_time, 60) local th_min = mod(floor(th_time / 60), 60) local th_hour = floor(th_time / 3600) if th_sec < 10 then th_sec = "0" .. th_sec end if th_min < 10 then th_min = "0" .. th_min end local th_remaining_time = th_hour .. ":" .. th_min .. ":" .. th_sec if th_min > 15 then SendChatMessage("Time: " .. th_remaining_time,SAY) else SendChatMessage("Time: " .. th_remaining_time .. " Queue available!",SAY) end else print("|cff6EB0DCHerald unable to announce time. The Battle is either in progress or you are in an instance or a Battleground.") end end end) </OnMouseDown> <OnMouseUp> testherald:SetScript("OnMouseUp", function() this:StopMovingOrSizing() end) </OnMouseUp>
When I load WoW or /console reloadui with the new formatting to the seconds and minutes, the frame is gone. If I change the conditional statement "if th_min > 15 then" to "if th_min <= 15 then", the frame is gone. Are there some sort of limitations to using conditional statements in XML? I've stripped my mod to the bare essentials to see if the code was conflicting with anything else and it doesn't seem to change anything.
Any guidance would be greatly appreciated.
-
Posted by jnwhiteh on Sat, 29 May 2010 09:36:37
Well the first thing that is REALLY confusing.. why are you doing :SetScript() in the script handlers? That doesn't seem to make any sense to me and its very much confusing everything.
Second, I don't put logic like this into my XML files for a reason. See the way we set handlers on CombatTracker or BagBuddy (depending on which book you have) to see how I normally would do it.
-
Posted by Drunk Cadaver on Sat, 29 May 2010 15:51:42
I feel stupid. I found that code somewhere in an example or I got it from another mod that did something similar to what I was looking to do... I don't remember.
I have been looking for this everywhere though and had it under my nose the entire time. Thank god I wasn't hunting rattlesnakes. lol I'll definitely jump into this chapter. I can already see where my mod has a lot of issues that need to be worked on. I can already see the answer to a lot of questions I had but didn't ask too. This chapter will definitely help. Thanks for the reply.
-
Posted by Drunk Cadaver on Sat, 29 May 2010 20:29:26
I rewrote a large amount of my mod and was able to reduce a lot of the code and remove 3 frames. All the problems I couldn't figure out are resolved as well. Thanks for pointing me in the right direction.
-
Posted by jnwhiteh on Sun, 30 May 2010 07:59:40
Ah, the simplification hammer wins again!