Quantcast StatusBar Time Best Practice? - WoWInterface
Thread Tools Display Modes
11-01-08, 12:19 AM   #1
HyperGig
A Cyclonian
Join Date: Jan 2008
Posts: 46
StatusBar Time Best Practice?

I'm new to making teh mods and i have a best practice question.

I have a StatusBar that i would like to use to keep track of a particular buff and i was wondering what the best way to do this is? Originally i was doing something like this...

Code:
               
local name, rank, icon, count, debuffType, duration, expirationTime, isMine, isStealable =UnitBuff("target",i)
local bar = getglobal("Form".."StatusBar1");
local left = (expirationTime - (time()-1225488545)) / duration; 
bar:SetValue(left);
..and stuck this function in the <OnUpdate> tags in the xml.

This can't be the best way to do this right? Like there is some sort of built in thing-a-ma-jig that does times and durations for you?

Thanks in advanced
  Reply With Quote
11-01-08, 01:05 AM   #2
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 151
1) you could store expirationTime in some variable, not to query it every time
2) or could do some thing like
bar:SetMinMaxValues(GetTime(),expirationTime)
when you initializing your timer and then just put bar:SetValue(GetTime()) in OnUpdate and you don't even need to store anything
3) you could limit amount of OnUpdate calls, but here it's unnecessary, onupdate func is very small already

This can't be the best way to do this right? Like there is some sort of built in thing-a-ma-jig that does times and durations for you?
no, for something involving time updating it's the only way.
Try to use AceTimer lib, but that's the same onupdate in more friendly way
  Reply With Quote
11-01-08, 08:52 AM   #3
HyperGig
A Cyclonian
Join Date: Jan 2008
Posts: 46
Thank you for your quick reply!!

It baffles me that we have to do this on every update. It just seems very inefficient that on every single update we are making these calls.

Also, is gettime() differant from Time()? Because i noticed that i have to subtract 1225488545 from Time() to make it comparable to expirationTime. Is GetTime() relative to expirationTime()? (aim not on a machine that plays wow so i cant test it now )
  Reply With Quote
11-01-08, 08:59 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,727
Well... You want your statusbar to update, right? Even if there *were* an event that Blizzard fired off to update buff times, it would probably happen in an onupdate, too.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-01-08, 09:27 AM   #5
lieandswell
A Cyclonian
 
lieandswell's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 45
Originally Posted by HyperGig View Post
This can't be the best way to do this right?
You used to have to use OnUpdate to make sure you always had the right time, especially for when buffs got refreshed, but it's not necessary anymore. There is a different way.

You can use an OnEvent function to call UnitBuff whenever any of the SPELL_AURA events in COMBAT_LOG_EVENT_UNFILTERED match the buff/unit you're looking for. Use that to set the duration and time left on the status bar. Then, have an OnUpdate that makes the bar smaller according to its own internal time counter using the local timeElapsed value supplied by OnUpdate. Whenever some adustment needs to happen -- the buff gets dispelled or refreshed, for example -- the OnEvent will re-calibrate the bar.

I hope that makes sense. It sounds more complicated, and does require more coding, but it's less work for the cpu overall because you're only doing math on local variables in the OnUpdate function. Blizz even said on the WoW UI forums that calling UnitBuff in an OnUpdate would probably be too much of a performance hit.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » StatusBar Time Best Practice?

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