Thread Tools Display Modes
09-06-08, 08:17 PM   #1
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
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?
  Reply With Quote
09-06-08, 08:28 PM   #2
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
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).
  Reply With Quote
09-06-08, 10:22 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
why is PEW of no use?
__________________
"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
09-06-08, 11:02 PM   #4
VincentSDSH
Non-Canadian Luzer!
 
VincentSDSH's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 350
Originally Posted by Seerah View Post
why is PEW of no use?
Didn't PEW use to be triggered when you zoned? (I know they mucked about with it a few years ago, can't recall how it's triggered now)

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.
  Reply With Quote
09-06-08, 11:26 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Ah yes, it does (had forgotten about that). PLAYER_LOGIN is your other option.
__________________
"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
09-07-08, 02:14 PM   #6
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
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???
  Reply With Quote
09-07-08, 02:22 PM   #7
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
p.s. I just tried ADDON_LOADED (testing arg1 for my addonname) and it has EXACTLY the same behaviour so I'm stumped...
  Reply With Quote
09-07-08, 02:24 PM   #8
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
I've always used "ADDON_LOADED" and it's never failed me (remembering to unregister it after it's fired ofc).
  Reply With Quote
09-07-08, 02:30 PM   #9
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
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
  Reply With Quote
09-07-08, 02:35 PM   #10
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by Tristanian View Post
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
Read everything I said and you won't get confused

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...

Last edited by kerrang : 09-07-08 at 02:43 PM.
  Reply With Quote
09-07-08, 02:55 PM   #11
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
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....
  Reply With Quote
09-07-08, 03:00 PM   #12
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Do you have errors enabled because if you copied and pasted that code then there are some glaring errors i.e.

MYTABLE = {"A","B","C")
should be
Code:
MYTABLE = {"A","B","C"}
and if you want it to output "ABC" then this:

for val in pairs(MYTABLE) do
MYSTRING = MYSTRING .. val
end
should be

Code:
for i, val in pairs(MYTABLE) do
   MYSTRING = MYSTRING .. val
end
  Reply With Quote
09-07-08, 03:08 PM   #13
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
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.
  Reply With Quote
09-07-08, 03:09 PM   #14
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
I typed the examples straight into the forum - they're EXAMPLES - do they LOOK like 'real' code to you?
  Reply With Quote
09-07-08, 03:16 PM   #15
Mikord
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 61
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
## Title: TestSV
## SavedVariables: TestSV
TestSV.lua
TestSV.lua
Code:
local function OnEvent(self, event, arg1)
 if event == "ADDON_LOADED" and arg1 == "TestSV" then
  self:UnregisterEvent("ADDON_LOADED") -- Don't need to know about others

  if not TestSV then TestSV = {} end
  TestSV.timesLoaded = (TestSV.timesLoaded or 0) + 1
  ChatFrame1:AddMessage("TestSV Times Loaded: " .. TestSV.timesLoaded)
 end
end

local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", OnEvent)
  Reply With Quote
09-07-08, 03:19 PM   #16
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
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"/> 
   <Frame name="OBI" visible="true" parent="UIParent"> 
      <Scripts> 
         <OnLoad>
            this:RegisterEvent("PLAYER_LOGIN"); 
         </OnLoad> 
         <OnEvent>
           if event == "PLAYER_LOGIN" then
             OBI_variablesloaded()
           end; 
         </OnEvent>
         <OnUpdate>
           OBI_update();
         </OnUpdate> 
      </Scripts> 
   </Frame>
Could this be part of the issue? Should I ditch the .XML files entirely (all my UI elements are created dynamically in the .LUA file)???
  Reply With Quote
09-07-08, 04:16 PM   #17
slizen
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 15
Originally Posted by VincentSDSH View Post
Didn't PEW use to be triggered when you zoned? (I know they mucked about with it a few years ago, can't recall how it's triggered now)
Why not use it and then just unregister it when it has run once?
  Reply With Quote
09-07-08, 04:51 PM   #18
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
Originally Posted by kerrang View Post
Could this be part of the issue? Should I ditch the .XML files entirely (all my UI elements are created dynamically in the .LUA file)???
It is possible. I usually point the script handlers to functions inside the lua when dealing with .xml files, you can either try to do that and see if it has any effect (imo it should) or ditch them entirely.
  Reply With Quote
09-07-08, 05:07 PM   #19
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
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????
  Reply With Quote
09-07-08, 05:34 PM   #20
Mikord
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 61
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
TestGSI.lua
TestGSI.lua
Code:
 ChatFrame1:AddMessage(GetSpellInfo(12294))
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » VARIABLES_LOADED - except they're not

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