1. 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.

    Same value each time?

    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.

    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)

    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?

    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).

    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.

    Can you provide your entire addon? Would like to see if I can replicate the behavior.

    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.

    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.

    My my, how embarassing... I was loading the file in the TOC and the XML. Problem solved. :p Thanks a bunch.