WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   StatusBar Time Best Practice? (https://www.wowinterface.com/forums/showthread.php?t=19039)

HyperGig 11-01-08 12:19 AM

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 :banana:

d87 11-01-08 01:05 AM

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

Quote:

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

HyperGig 11-01-08 08:52 AM

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 :rolleyes:)

Seerah 11-01-08 08:59 AM

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.

lieandswell 11-01-08 09:27 AM

Quote:

Originally Posted by HyperGig (Post 107659)
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.


All times are GMT -6. The time now is 06:24 PM.

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