How would I tell me addon to do something once per second? For every second while I'm doing something (in combat for example). So for every second I was in combat (on the interval) I want to take a snapshot of my hp, and store the value returned so I could call it later. i also want it to work the whole time im in combat.
example because i dont think that was clear at all:
0 second: enter combat:start recording
1 second: record playerHP1
2 second: record playerHP2
3 second: leave combat:stop recording
print: ("At 1 second your health was " .. playerHP1)
print: ("At 2 second your health was " .. playerHP2)
[php]
CombatRecord = {}
local addon = CombatRecord
local db = {}
addon.db = db
local frame = CreateFrame("Frame")
local currentCombat
local delay, interval = 0 , 1
frame:SetScript("OnUpdate", function(frame, elapsed )
delay = delay + elapsed
if delay > interval then
currentCombat[GetTime()] = UnitHealth("player")
delay = 0
end
end)
frame:SetScript("OnEvent", function(frame, event, ...)
if type(addon[event]) == "function" then
addon[event](addon, event, ...)
end
end)
function addon:PLAYER_REGEN_DISABLED()
currentComabt = {}
end
function addon:PLAYER_REGEN_ENABLED()
db[#db+1] = currentCombat
end
I see it more like... if you use a lib (one that doesn't run too heavy, which the Ace3-libs claim to be (not heavy that is)) you're using tested and true code instead of your own stuff which can have a myriad of bugs in it.
Especially when they're drycoded by someone :p.
Of course, these "code bits" might already be second nature to you...
Again I add the "me = noob" disclaimer. Just throwing out what I'm thinking so you guys can refute or confirm it.
Things change when you're using a non-tested-to-the-bone lib like LibMindReader or sth ;)
AceTimer is always good to use if you have long runtime timers. Having umpteen frames running their own little timer implementations does cost more CPU than letting AceTimer do it.
Not that it's a HUGE issue... but the right answer still is "Use AceTimer".
(No, if you only do a short duration timer once in a while, it of course doesn't matter in a measurable way. Use head = win.)
example because i dont think that was clear at all:
0 second: enter combat:start recording
1 second: record playerHP1
2 second: record playerHP2
3 second: leave combat:stop recording
print: ("At 1 second your health was " .. playerHP1)
print: ("At 2 second your health was " .. playerHP2)
[php]
CombatRecord = {}
local addon = CombatRecord
local db = {}
addon.db = db
local frame = CreateFrame("Frame")
local currentCombat
local delay, interval = 0 , 1
frame:SetScript("OnUpdate", function(frame, elapsed )
delay = delay + elapsed
if delay > interval then
currentCombat[GetTime()] = UnitHealth("player")
delay = 0
end
end)
frame:SetScript("OnEvent", function(frame, event, ...)
if type(addon[event]) == "function" then
addon[event](addon, event, ...)
end
end)
function addon:PLAYER_REGEN_DISABLED()
currentComabt = {}
end
function addon:PLAYER_REGEN_ENABLED()
db[#db+1] = currentCombat
end
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
function addon:PrintCurrentCombat()
for k,v in pairs(currentCombat) do
print("Time: "..(k or ""), "HP: "..(v or ""))
end
end
function addonPrintHistorical(i)
if db[i] then
for k, v in pairs(db[i]) do
print("Time: "..(k or ""), "HP: "..(v or ""))
end
end
end
[/php]
make a macro
/run CombatRecord:PrintCurrentCombat()
Use self implemented stuff for specific things that are very optimized.
Libs don't make your addon better, just bloated if used wrong :D
Especially when they're drycoded by someone :p.
Of course, these "code bits" might already be second nature to you...
Again I add the "me = noob" disclaimer. Just throwing out what I'm thinking so you guys can refute or confirm it.
Things change when you're using a non-tested-to-the-bone lib like LibMindReader or sth ;)
Not that it's a HUGE issue... but the right answer still is "Use AceTimer".
(No, if you only do a short duration timer once in a while, it of course doesn't matter in a measurable way. Use head = win.)
Although that in itself might be justification to use AceTimer, so that you wouldn't have to write your own.