Hi, if you want to execute code every second no matter what, you could do it like this:
Code:
local lastCall = GetTime()
local updateFrame = CreateFrame("Frame")
updateFrame:SetScript("onUpdate", function()
if GetTime() - lastCall > 1 then
lastCall = GetTime()
-- Your stuff here that gets executed every second.
end
end)
Or alternatively (I don't know, maybe because not using GetTime() is more efficient?):
Code:
local timePassed = 0
local updateFrame = CreateFrame("Frame")
updateFrame:SetScript("onUpdate", function(elapsed)
timePassed = timePassed + elapsed
if timePassed > 1 then
timePassed = 0
-- Your stuff here that gets executed every second.
end
end)
But you know that there are also the game
EVENTS, which you can register for, such that your code only gets executed after the respective event?