Thread Tools Display Modes
04-15-20, 06:02 PM   #1
timpoole247
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2020
Posts: 7
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?
  Reply With Quote
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
04-17-20, 02:33 AM   #3
timpoole247
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2020
Posts: 7
Thankyou, exactly what I needed.
  Reply With Quote
04-18-20, 03:08 PM   #4
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
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.
  Reply With Quote

WoWInterface » Classic - AddOns, Compliations, Macros » Classic - AddOn Help/Support » How to keep data, up to date

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off