WoWInterface (
-   Classic - AddOn Help/Support (
-   -   How to keep data, up to date (

timpoole247 04-15-20 06:02 PM

How to keep data, up to date
Hi, I'm working on my first addon. Its a profession tracker, to show where trainers are, herb/ore tracking status, what veins + herbs I can or can't harvest and what skill I need to harvest them, etc etc.

Anyway, as soon as I login to the world, I toggle the addon via slash command and it correctly shows skill levels and tracking status etc, but if I gain skills, or change from herb to ore tracking, it doesn't update.

How do I keep the data up to date? I basically want to refresh my addon every second. How would I go about doing this?

LudiusMaximus 04-16-20 01:07 AM

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?

timpoole247 04-17-20 02:33 AM

Thankyou, exactly what I needed.

Urtgard 04-18-20 03:08 PM

For timers there is C_Timer:

But in this case you should look into events like LudiusMaximus mentioned it.

All times are GMT -6. The time now is 10:10 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI