-
Posted by res1233 on Wed, 09 May 2012 23:00:18
For some reason my code is printing twice, and I can't figure out why. Any help would be appreciated.
local armorFrame = CreateFrame("Frame","Test") local elapsedTotal=0 local curAvoidance=GetDodgeChance()+GetBlockChance()+GetParryChance()+5 armorFrame:SetScript("OnUpdate" , function(self, elapsed) elapsedTotal=elapsed+elapsedTotal if elapsedTotal>=5 then elapsedTotal=0 if curAvoidance~=GetDodgeChance()+GetBlockChance()+GetParryChance()+5 then curAvoidance=GetDodgeChance()+GetBlockChance()+GetParryChance()+5 print("Avoidance is now at "..curAvoidance) end end end)
Pretty simple code... Should need no explanation.
-
Posted by jnwhiteh on Wed, 09 May 2012 23:10:50
Same value each time?
-
Posted by res1233 on Wed, 09 May 2012 23:23:33
Yes, exactly the same, and as you may know, the value printed is a very long decimal. The numbers are all identical, so for some reason it's executing that same exact line twice. It's very strange.
-
Posted by stolenlegacy on Thu, 10 May 2012 22:03:01
Debug time.
if elapsedTotal>=5 then elapsedTotal=0 local avoidSum = GetDodgeChance()+GetBlockChance()+GetParryChance()+5 if curAvoidance~=avoidSum then print("Different:",curAvoidance,avoidSum) curAvoidance=avoidSum print("Avoidance is now at "..curAvoidance) end end
See if that gives you/us any hints. (Also saves you a very minor amount of performance by not calculating stuff twice)
-
Posted by res1233 on Fri, 11 May 2012 13:24:01
Sorry about taking so long to get back to you! This time, both prints are printed twice. Here's the output:
Different: 100.96647071838 100.40528678894 Avoidance is now at 100.40528678894 Different: 100.96647071838 100.40528678894 Avoidance is now at 100.40528678894
Very strange behavior. The only thing I could think of is some sort of OnUpdate bug.
One question: Is it possible that variable setting is slower than OnUpdate and this is some sort of multi-threading issue?
-
Posted by stolenlegacy on Fri, 11 May 2012 14:17:05
Shouldn't be. Try using keys on self (so self.curAvoidance instead of simply "avoidance") to make sure (I'm absolutely positive these work, I use them to throttle OnUpdate all the time).
-
Posted by res1233 on Fri, 11 May 2012 16:39:34
Doesn't seem to do anything. There is nothing in my code that could explain this except for some unexpected OnUpdate behavior. I tried putting a delay in my code, but that delays everything but world stuff, so it did nothing, as expected.
-
Posted by stolenlegacy on Fri, 11 May 2012 21:08:10
Can you provide your entire addon? Would like to see if I can replicate the behavior.
-
Posted by res1233 on Sat, 12 May 2012 01:20:54
That's fine.
local k=0 local delayNum=0 MYSCRIPT_TITLE = "Baggit"; local armorFrame = CreateFrame("Frame","Test") local elapsedTotal=0 local curAvoidance=GetDodgeChance()+GetBlockChance()+GetParryChance()+5 armorFrame:SetScript("OnUpdate" , function(self, elapsed) elapsedTotal=elapsed+elapsedTotal if elapsedTotal>=5 then elapsedTotal=0 local avoidSum = GetDodgeChance()+GetBlockChance()+GetParryChance()+5 if curAvoidance~=avoidSum then print("Different:",curAvoidance,avoidSum) curAvoidance=avoidSum print("Avoidance is now at "..curAvoidance) end end end) SLASH_BLAH1 = "/delay" SlashCmdList["BLAH"] = function(msg, editBox) if tonumber(msg) then local curProfile = debugprofilestop() while debugprofilestop()<curProfile+tonumber(msg) do end end end
Slightly messy. I have some code in there that I never got around to removing. Essentially this is just an addon that I wrote to do things I needed, one's a delay for my macros, the other is an avoidance reporter. It's possible these two are conflicting somehow, but I doubt it.
EDIT: I actually do have a small UI going. It's disabled ATM because I never got around to completing it; didn't see the need, but that's what MYSCRIPT_TITLE is for.
-
Posted by stolenlegacy on Sat, 12 May 2012 07:36:12
It's not doing that for me. If I had to blindly guess: you're loading the file twice. Check your ToC file. If that's not it, print the 'self' in either of the two print lines.
-
Posted by res1233 on Sat, 12 May 2012 14:48:00
My my, how embarassing... I was loading the file in the TOC and the XML. Problem solved. :p Thanks a bunch.