Getting Player and Realm Name At Load Time
From WoWWiki
The 1.5.0 patch made this process much simpler than in previous patches, and this document has been updated correspondingly. It's probably still worth reading the section on game world initialization though.
Contents |
Player Name
Since the 1.5.0 patch the player's name (and class, race, and sex) are all available right away, since the client knows at least that much about who you are. You can simply call UnitName("player") at any point in your addon and you'll get the correct value.
If you need more than just the name, you should read about game world initialization below:
Realm Name
The current realm name is saved into a configuration variable called realmName, and can be retrieved using GetCVar("realmName"). This is set before the FrameXML UI is initialized, so will always be set by the time an addon is loaded.
You can also call GetRealmName() for the same result.
Game World Initialization
When first logging into the game, your UI is initializing at the same time as the game server is creating your view of the game world. Because of this, not everything is known to the client when an addon is initializing (This used to include player name, but that has been changed in the 1.5.0 patch). The key steps during startup are:
- Base (FrameXML) code loaded. -- The standard UI code is loaded according to the FrameXML.toc file.
- UI Addons loaded (In dependency-satisfying order) -- Each addon is loaded (in order to satisfy dependencies), according to its .toc file.
- Saved Variables Loaded -- The SavedVariables.lua file is executed, and then the VARIABLES_LOADED event fires.
- Player Enters World -- Once the majority of world initialization is complete, the PLAYER_ENTERING_WORLD event fires, at this point it's safe to start interacting with the world (Though it's not necessarily fully in sync, you may receive update events subsequently to fill in some blanks).
Startup after a UI reload, rather than a fresh login follows the same steps, but the game world is already initialized right away, so most queries work immediately, rather than having to wait for PLAYER_ENTERING_WORLD. If your addon makes any assumptions during initialization regarding the state of the game world, it's worthwhile checking it initializes correctly under both scenarios.
Chronos
If you have the addon Chronos, and want to run some code after initialization, you can simply do:
Chronos.afterInit(IntializeSetup);
Where InitializeSetup is replaced by the the name of a function in your addon that needs to be called after initialization.
