Help with using expirationTime
Hey there! It's me again- Didn't know whether it's best to make a new thread for a new question or not.
I've been having difficulty with getting the remaining time on a buff - I'm probably missing something obvious but all my many google searches keep bringing me to threads with solutions that don't work, but I noticed that these threads are from many years ago and things may have changed since then. Essentially I just want something to happen when a particular buff has only 1 minute left (or 10 seconds, as i've been using for testing purposes on a shorter buff). I'm aware that expirationTime needs to be used along with GetTime() to convert it to seconds- but the methods that i've tried for doing this haven't worked. I had some luck using this snippet from a much older thread on this forum: Code:
for i=1,40 do My last try was this: (please excuse my messy/probably wrong code, I'm a beginner at coding but I tried my best!) Code:
for i=1,40 do |
Is this all of your code? The loop will only run once on login/reload.
You could take a look at the events when you apply or update a buff. Then check when the buff expires and use C_Timer to show the warning at the right time. Or run your loop with an OnUpdate script or some other event. I've never really worked with buffs, so not sure what and how often the events are called. A bit about events: https://wow.gamepedia.com/Handling_events |
This appears to be how nUI does it and I haven't seen it be too far out with its calculations
Lua Code:
nUI calls the function that contains this code using a function ( updateAuraInfo( unit_id, unit_info ) ) for each unit. Which is called whenever the custom OnAuraUpdate function is run every update cycle and there is something to process in its UpdateQueue. Our OnAuraEvent function handles the following events: frame:RegisterEvent( "ADDON_LOADED" ); frame:RegisterEvent( "PLAYER_ENTERING_WORLD" ); frame:RegisterEvent( "UNIT_AURA" ); In ADDON_LOADED we set up the aura buttons and refresh the callbacks ( which then updates the auras ) In PLAYER_ENTERING_WORLD we refresh the callbacks again In UNIT_AURA we add the aura and unit it has affected to an update queue to be acted on the next time the game does an update cycle. I haven't played with C_Timer myself so not sure what restrictions if any there are in how it can be used but in *theory* you could do something like the following but I suspect it would just set up multiple timers, so you may have to have some sort of list of timers and whether they can be re-used: Lua Code:
I've added name in there in case there is a glitch and aura i is no longer aura name. How that would occur I don't know. How much of the aura system is accessible I don't know myself either. I recall limits on only seeing your own auras on other players or npcs. But not sure if that was Classic or Retail. |
Quote:
|
Quote:
|
Thank you for your explanations and your help, it's very kind of you! I think I may be understanding wrong, because I tried both solutions you posted and I can't seem to get them to work - This was the little test I wrote, am I doing something stupid ive just overlooked here?
Lua Code:
|
Where are you creating the frame, and where are you telling it to run your function on that event?
|
UNIT_AURA tells you when you gain/loose an aura (you might be waiting a while for this to fire). To update the time left on an aura you need to use an OnUpdate script (which happens every time the frame is updated ie. lots)
Lua Code:
Or a C_Timer as mentioned above but you need to check more often or at a known time rather than when a random event fires. |
Thanks everybody for the extra pointers, I'm very grateful! Seerah, here is my complete code right now (pardon how ugly my button looks, i'm planning to pretty it up once it all works. I also plan to find the aura by name in that if statement, not just by only having ten seconds remaining.) I put all the suggestions in, to my best ability - it's not working but I'm certain that's just because of a rookie error on my end.
Lua Code:
|
I think this is more what you're looking for (I'm using Arcane intellect if you have a Mage or choose another spell to test that doesn't cost). I'm only counting down a couple of seconds from the start of the buff being applied so do with the timing as you will (x seconds before it runs out or whatever). Also printing the countdown so you can see it running.
Once a frame is hidden it's OnUpdate stops so I'm using a second frame for that and checking the event then using it to show the button if it finds the buff. This is where C_Timer is possibly a useful alternative but, this is just a basic starter example of how it might work. I've started with the button hidden but that's up to you if you want it to be the primary source of the buff rather than just a popup reminder. functions, variables etc. declared as local can't be used until after they're declared and only within the same code chunk. Lua is case sensitive so UIparent is not the same as UIParent. There are a bunch of other errors, if you don't have them installed I would suggest getting BuggGrabber and Bugsack so you can see when and mostly where/what your errors are. Lua Code:
|
Quote:
Also, you should consider buffs getting reapplied before their timer expires or the user canceling buffs. Both of these make C_Timer.After() a poor candidate. Quote:
|
Quote:
I did say it was a theory :) My theory was that C_Timer may be an alternative to the update routine as long as you do the appropriate checks and include changes based on the UnitAura event to make adjustments accordingly ... adjusting the timer ( if possible ) to reflect the new value due to early re-application and cancel the timer ( again if possible ) so that it's function doesn't get called. nUI currently uses the update routine and UnitAura and works fine for what it does with them. But it's good to know that C_Timer may not be the best option for some areas of wow for if and when I ever consider it. |
While C_Timer.After() can't be canceled, Blizzard has a Lua-implemented extension that can, C_Timer.NewTimer(). This returns a ticker object with a the method ticker:Cancel().
Note, the base C_Timer.After() still fires, but the middleman function then decides whether or not to pass it along to your callback. |
Quote:
|
Thank you fizzlemizz for correcting some of my mistakes- I'll install that debugger and go through it soon to find the others! Consider my original question resolved as I don't want to bother you all anymore with fixing my code for me in your own time :)
EDIT: I managed to iron out the bugs and have a working addon now, thank you so much! I don't plan on sharing it widely except with friends, but I've added credit at the top to all of you just in case. |
All times are GMT -6. The time now is 01:19 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI