WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   VARIABLES_LOADED - except they're not (https://www.wowinterface.com/forums/showthread.php?t=18078)

kerrang 09-06-08 08:17 PM

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?

Tristanian 09-06-08 08:28 PM

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

Seerah 09-06-08 10:22 PM

why is PEW of no use?

VincentSDSH 09-06-08 11:02 PM

Quote:

Originally Posted by Seerah (Post 101537)
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.

Seerah 09-06-08 11:26 PM

Ah yes, it does (had forgotten about that). PLAYER_LOGIN is your other option.

kerrang 09-07-08 02:14 PM

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

kerrang 09-07-08 02:22 PM

p.s. I just tried ADDON_LOADED (testing arg1 for my addonname) and it has EXACTLY the same behaviour so I'm stumped...

Slakah 09-07-08 02:24 PM

I've always used "ADDON_LOADED" and it's never failed me (remembering to unregister it after it's fired ofc).

Tristanian 09-07-08 02:30 PM

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

kerrang 09-07-08 02:35 PM

Quote:

Originally Posted by Tristanian (Post 101588)
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

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

kerrang 09-07-08 02:55 PM

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

Slakah 09-07-08 03:00 PM

Do you have errors enabled because if you copied and pasted that code then there are some glaring errors i.e.

Quote:

MYTABLE = {"A","B","C")
should be
Code:

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

Quote:

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

Code:

for i, val in pairs(MYTABLE) do
  MYSTRING = MYSTRING .. val
end


Tristanian 09-07-08 03:08 PM

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.

kerrang 09-07-08 03:09 PM

I typed the examples straight into the forum - they're EXAMPLES - do they LOOK like 'real' code to you?

Mikord 09-07-08 03:16 PM

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)


kerrang 09-07-08 03:19 PM

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)???

slizen 09-07-08 04:16 PM

Quote:

Originally Posted by VincentSDSH (Post 101539)
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?

Tristanian 09-07-08 04:51 PM

Quote:

Originally Posted by kerrang (Post 101601)
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.

kerrang 09-07-08 05:07 PM

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

Mikord 09-07-08 05:34 PM

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


All times are GMT -6. The time now is 12:36 AM.

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