WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Classic - AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=179)
-   -   How to keep data, up to date (https://www.wowinterface.com/forums/showthread.php?t=57939)

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:

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?

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: https://wow.gamepedia.com/API_C_Timer

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


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

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI