I'm trying to use the pattern of waiting till x seconds have passed before running the update code, but for some reason once it gets passed the if statement it runs the update twice.
Code is below, should count up 1 every 8 seconds, instead counts up 1 then another 1 instantly every 8 seconds. e.g.
00:00: 1
00:00: 2
00:08: 3
00:08: 4
00:16: 5
00:16: 6
etc
Code:
local MyAddon = CreateFrame("Frame","MyAddon",UIParent)
MyAddon.Units = {}
MyAddon_UpdateInterval = 8.0
loaded=false
e=0
function MyAddon:Initialize(self)
loaded=true
end
function MyAddon:Update()
e = e + 1
print(e)
end
local timeElapsed = 0;
MyAddon:SetScript("OnUpdate", function(self,elapsed)
timeElapsed = timeElapsed + elapsed
if(timeElapsed > MyAddon_UpdateInterval) then
timeElapsed = 0.0
MyAddon:Update()
end
end)
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
<Script File="addon.lua" />
</Ui>
It seems like it's a concurrency issue, but that would break the whole idea of slowing the update method wouldn't it?
I also tried putting in an update counter so that it would only update every 5 calls, but it still behaved the same way.