![]() |
Need event when world is loaded, game is playable
My addon needs to display some information to the player when they log in using the alert system, similar to how you get notices about achievements being earned on log in or garrison/order missions being completed. The problem is that all the methods I've found to do this are unreliable.
I'm looking for an event that is called when the game is actually playable: The player sees their character in the world and can now start playing (moving the character around, etc.). It should preferably be called after any loading screen has finished its job, but I will settle for one that triggers A) when the character "enters the world" for the first time from the character selection screen, and B) when the UI is reloaded (as from a /reload command or the "Reload UI" button on the in-game AddOn List). The events I've been using all trigger too soon, while the game world is still loading. I've tried using C_Timer to add a delay, but this only works sometimes: It never works after a /reload, but it usually does when entering the world from character selection (but not always! the extra long loading screens in Dalaran seem to sometimes break it, for one). Frustratingly, the C_Timer functions apparently start counting down at some point while the loading screen is still visible (and that point seems to happen sooner when you do a /reload than it does when entering from character selection). For my purposes, the event I'm looking for needn't happen at the exact moment the player character is playable, just so long as it is reliably triggered within a couple of seconds after that point. |
Neither PLAYER_LOGIN nor PLAYER_ENTERING_WORLD work for you?
|
I've tried both of them individually and they don't work consistently. It's as described above: Usually on entering the game, never on /reload.
The alerts involve the in-game calendar, so I thought I'd try using OpenCalendar() inside PLAYER_ENTERING_WORLD and watching for CALENDAR_UPDATE_EVENT_LIST, but I end up with mostly the same problem, with one (rather odd) difference: The alerts do appear as intended after the first /reload... but not on any subsequent /reload (until you go back to character selection). I can tell the code that makes the alerts appear is called (since I added print messages), but the frames do not appear unless I put in so many alerts that there are too many to display at once, in which case the first batch are not shown but the rest (which would have gone to the queue) are. I should note that the alerts I'm using are created using AlertFrame:AddQueuedAlertFrameSubSystem() with a custom template. If I set the C_Timer to something especially long, the alerts will appear then, as well -- but that's not a good solution because the ideal wait time would vary from PC to PC and also can vary depending on what is being loaded, and we'd have an especially long delay in those cases where C_Timer wasn't counting down early (e.g. when entering the world from character select). (I really don't understand why C_Timer is counting down during the /reload process. This seems like a bug.) It would be much easier if I had an event that reliably triggered when the game world is fully ready. |
Lua Code:
ADDON_LOADED will always fire on login and on reload, but not on loading screens or any subsequent loading in the game. While this might not be the best basis for showing your toast, you can use it as backbone to determine when to start things off. |
Quote:
You could try at PLAYER_ENTERING_WORLD: Code:
if not IsAddOnLoaded("Blizzard_Calendar") then |
In most cases the events prescribed do not load in any significant order. The way I have found, that works for me, is to wait until all three, replacing PLAYER_LOGIN since this occurs only once during a session, have been triggered and most information is available. This should include on ReloadUI but I am unsure if it will work for things like dungeon in/out. However, I am unaware if this will remedy your issue so I apologize in advance if this has wasted your time.
Lua Code:
|
Ah, getting info from the calendar. That's helpful to know. ;)
In my Bear in Mind addon, I have the Blizzard_Calendar listed as a dependency. I then looked through the UI source code and found how they update and gather calendar info. You can look in BiM.lua if you like to see how I gather the day's events (just don't straight up copy it ;) ). The relevant code is at the end of the BiM.PlayerLogin function, which then also calls the CheckForCalendarEvents function above that. |
I already successfully grab the information I need from the calendar, and did so even if I was using only PLAYER_LOGIN or PLAYER_ENTERING_WORLD, so I don't think that's the problem.
According to this, PLAYER_ENTERING_WORLD fires after ADDON_LOADED and is considered the last startup event. But C_Timer starts ticking down while the loading screen is still visible when you do /reload (again, I think this is a bug), so it doesn't work properly with alert frames. Is there not an event that fires when the game is actually playable, player in the world? Maybe one that actually signifies something besides "game now playable" but will reliably occur at that point? It could be one that triggers many times, even, just so long as the first time it triggers after PLAYER_ENTERING_WORLD is when the game world is shown. |
I had a long seach for this as well and the best I could do was this:
Lua Code:
|
I just tried PET_JOURNAL_LIST_UPDATE and it was still called too soon. Any other ideas?
|
As far as I know, noone has found a silver bullet event after PLAYER_ENERING_WORLD to cover all situations. Even Blizzard uses multiple events to cover login, logout/login and /reload scenarios for different parts of the game.
|
Sorry for the double post, but I seem to have found a workaround.
This doesn't work reliably: Code:
C_Timer.After(3, function() Code:
C_Timer.After(0, function() Edit: Turns out it wasn't a double post. Thanks, Fizzlemizz! ;) |
Quote:
Trying to support /reload is a niche case and you should just make sure your code doesn't throw any errors. Ideally, nobody should need to use it in a normal session. It only exists because sometimes mistakes happen. You shouldn't need to complicate your code more covering other addons' problems. |
All times are GMT -6. The time now is 06:34 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI