WoWInterface - View Single Post - How to keep data, up to date
View Single Post
04-16-20, 01:07 AM   #2
A Chromatic Dragonspawn
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 193
Hi, if you want to execute code every second no matter what, you could do it like this:

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.
Or alternatively (I don't know, maybe because not using GetTime() is more efficient?):

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.

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