VARIABLES_LOADED - except they're not
I have some code in my addons which is called when VARIABLES_LOADED fires
It relies on SavedVariables - and it seems that on initial login, they are NOT set when VARIABLES_LOADED fires - tho they tend to be on /console reloadui This is obviously a bug (or that event has a WAY misleading name!) Where SHOULD I put such code - I only want it executed once at each login (so PLAYER_ENTERING_WORLD is no use) and SavedVariables must be set before it runs Any ideas? |
I don't really understand why VARIABLES_LOADED doesn't work for you, it should ensure that all non-lod addons have finished loading and their savedvars are availaible. The only other option, is PLAYER_LOGIN I guess (if you don't want to use PLAYER_ENTERING_WORLD).
|
why is PEW of no use?
|
Quote:
One trick you might explore is to have VAR_LOADED call a delay timer (aka single-execute Metrognome event) or, as I do with mods that have to bootstrap when not in combat, have it check for your vars and, if not found, set up the delay and immediately exit. The function Metrognome could trigger would be the bootstrap for your mod. |
Ah yes, it does (had forgotten about that). PLAYER_LOGIN is your other option.
|
I've been playing with this (whilst watching the Warhammer forums and laughing a lot - but that's another story) and it seems that (on live and BETA)
PEW fires on all zoning (instance/continent/expansion) PL fires on all zoning EXCEPT instances... VL is 100% unreliable the first time you login to a character - but is 100% reliable from that point forward (e.g. reloadui) Another thing I've noticed - which is ever weirder - is that a variable declared and assigned at the highest level in my lua has NO value on the first VARIABLES_LOADED either.... e.g. MYSTRING = "" MYTABLE = {"A","B","C") MYVLFUNC() -- called on VARIABLES_LOADED for val in pairs(MYTABLE) do MYSTRING = MYSTRING .. val end end With code like that, the first time I login MYSTRING will be blank - a reloadui and it will be "ABC" - logout and back in and it's blank again and so on... Something is ROYALLY screwed here??? |
p.s. I just tried ADDON_LOADED (testing arg1 for my addonname) and it has EXACTLY the same behaviour so I'm stumped...
|
I've always used "ADDON_LOADED" and it's never failed me (remembering to unregister it after it's fired ofc).
|
I'm puzzled. Is MYSTRING a savedvar (declared in your .toc as a savedvar) and if so why do you need to define it at the highest level of your file ? You should only be setting it, if its value doesn't exist. If there's something else you want to achieve, why not describe it clearly, because so far I can't see the reason why you need to use the VL event :p
|
Quote:
TO repeat: even if I refer to non-savedvars (as in the example above) they are NOT assigned when the first VARIABLES_LOADED/ADDON_LOADED event fires... I want to use GetSpellInfo() in this function now anyway - and that DEFINATELY doesn't work at the point VARIABLES_LOADED fires - so... I'm putting this down as another "shoddy Blizzard code" thing and rewriting my functions to work from a more reliable event (at least PLAYER_LOGIN doesn't fire TOO often) as I speak... |
PLAYER_LOGIN is working quite nicely - thanks for that suggestion.
I have to do a basic check to stop it refiring on zoning - but that doesn't happen too often so it's no big overhead. The best bit is that things like GetSpellInfo() work when PLAYER_LOGIN fires and you can write things into the chatframe for debugging - something that you can't do in VARIABLES_LOADED or ADDON_LOADED.... |
Do you have errors enabled because if you copied and pasted that code then there are some glaring errors i.e.
Quote:
Code:
MYTABLE = {"A","B","C"} Quote:
Code:
for i, val in pairs(MYTABLE) do |
Kerrang if you want to work with spell related API you can also try SPELLS_CHANGED, it should normally fire after VL and before PL, the thing is, since it also fires on other occasions you should probably unregister it right afterwards. But for all intends and purposes PLAYER_LOGIN should provide enough UI info to cover your needs.
|
I typed the examples straight into the forum - they're EXAMPLES - do they LOOK like 'real' code to you?
|
Without seeing all your code it's hard to pinpoint your problem, but I've never had a problem with ADDON_LOADED firing before the saved vars are loaded.
In fact, here is some sample code that I just tested and it worked every time for 20 logout/login cycles. The times loaded incremented as expected every time without fail. TestSV.toc Code:
## Interface: 20400 Code:
local function OnEvent(self, event, arg1) |
My addons (because I just tend to copy each one from the last) still use the 'old fashioned' approach of creating a frame in the .XML file and registering events there
e.g. Code:
<Script file="OBI.lua"/> |
Quote:
|
Quote:
|
I just rewrote an addon to use a Frame created in the .LUA - assigned it's events etc. and dumped the .XML file.
Tested it - working AOK - except that on restarting WOW I find that PLAYER_LOGIN does NOT have access to things like GetSpellInfo - at least not the first time you login (it seems to be OK on reloadui's)... That's VL, PEW and PL which don't allow me to do something really, really simple and I'm losing patience with this ****... All I'm trying to do is create a Frame (options/config panel), add some Widgets to it and and stick some text (derived from savedvariables and using GetSpellInfo()) into one of the widgets - it should happen only once, when a person logs in (obviously) - and it should not be this hard???? |
GetSpellInfo exists before addons are loaded. You don't need to wait for any events.
Tested the following and it prints Mortal Strike as expected: TestGSI.toc Code:
## Interface: 20400 Code:
ChatFrame1:AddMessage(GetSpellInfo(12294)) |
All times are GMT -6. The time now is 12:36 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI