View Single Post
04-16-20, 01:07 AM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
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?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~

Last edited by LudiusMaximus : 04-16-20 at 01:16 AM.
  Reply With Quote