Thread Tools Display Modes
07/09/20, 05:07 AM   #1
DarkPhalanx
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 6
What is the best practice to apply savedvariabled

Can anyone explain me what the best practice is to apply the savedvariables between a interface reload/logon of the game.

Currently I call all my addons functions when the addon is loaded again. For example my addons enabled you to rearrange the actionbar buttons. When the ui reloads they will reset to the games default position. I then call the function that set their pos based on the users saved variables. Another one for example hides the keybind text.


Do I call each function after the addon is loaded?

(I have searched the wiki and the forum before posting this )
  Reply With Quote
07/09/20, 05:16 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
You should simply wait for the EVENT_ADD_ON_LOADED before doing anything. When that fires, you can be certain that the saved vars have been loaded.

Lua Code:
  1. -- Here MyAddOnSavedVar is nil and if you assign any value it will be overwritten later
  2.  
  3. EVENT_MANAGER:RegisterForEvent("MyAddOnEventNamespace",  EVENT_ADD_ON_LOADED, function(_, addOnName)
  4.     if addOnName == "MyAddOn" then
  5.         EVENT_MANAGER:UnregisterForEvent("MyAddOnEventNamespace", EVENT_ADD_ON_LOADED)
  6.         -- Here MyAddOnSavedVar is either nil if it didn't exist, or the previously stored value
  7.     end
  8. end)
  Reply With Quote
07/09/20, 05:20 AM   #3
DarkPhalanx
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 6
Yes I'm doing that, so in that function I placed my functions with the paramaters pointing to the savedvars. It's normal for every Addon to basically have to reapply the settings for the addon to the users interface?
  Reply With Quote
07/09/20, 05:22 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
And in addition EVENT_PLAYER_ACTIVATED will fire as all was loaded and you are ready "to run" with your char ingame.
It will even fire after a reloadui, zone changes and other things where a loading screen appears.

Hint: The chat will be ready for output after this event has fired! So debug messages you send to the chat before (e.g. at EVENT_ADD_ON_LOADED) cannot be seen in the chat, except you use other libraries (LibDebugLogger) with it's own UI (DebugLogViewer) or addons like pChat which enable a history to buffer send messages before player activated event -> showing the cached messages then.
  Reply With Quote
07/09/20, 06:21 AM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Originally Posted by DarkPhalanx View Post
Yes I'm doing that, so in that function I placed my functions with the paramaters pointing to the savedvars. It's normal for every Addon to basically have to reapply the settings for the addon to the users interface?
Not sure what you mean? The user interface ceases to exist when you log out or use reloadui. It is built completely fresh from zero every time, so of course your addon needs to apply all its settings to it when it loads.
  Reply With Quote
07/09/20, 06:25 AM   #6
DarkPhalanx
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 6
Originally Posted by sirinsidiator View Post
Not sure what you mean? The user interface ceases to exist when you log out or use reloadui. It is built completely fresh from zero every time, so of course your addon needs to apply all its settings to it when it loads.
Ok, thanks that verifies my assumption.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » What is the best practice to apply savedvariabled

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