ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   What is the best practice to apply savedvariabled (https://www.esoui.com/forums/showthread.php?t=9266)

DarkPhalanx 07/09/20 05:07 AM

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

sirinsidiator 07/09/20 05:16 AM

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)

DarkPhalanx 07/09/20 05:20 AM

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?

Baertram 07/09/20 05:22 AM

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.

sirinsidiator 07/09/20 06:21 AM

Quote:

Originally Posted by DarkPhalanx (Post 41769)
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.

DarkPhalanx 07/09/20 06:25 AM

Quote:

Originally Posted by sirinsidiator (Post 41771)
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.


All times are GMT -6. The time now is 10:14 AM.

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