Quantcast How to make my addon load earlier? - ESOUI
Thread Tools Display Modes
08/30/18, 09:06 AM   #1
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
How to make my addon load earlier?

So I recently made my own little addon which is supposed to execute a simple single command.
My intention to make this addon was that I wanted to play the game with spoken language in german and written language in english. This is doable by starting the game in german and then executing a certain command.
I decided to put that command into an addon file so that it automatically does the above whenever I start the game.
In theory it should work but I have a feeling that the addon executes too late, this ends up in having half of all texts still in german.
An additional /reloadui fixes the problem however.

Is there a possibility to make the command execute earlier (if I am even correct with my assumption)?

My code looks like this:
Code:
AdvancedLanguageSelector = {}
AdvancedLanguageSelector.name = "AdvancedLanguageSelector"
 
function AdvancedLanguageSelector:Initialize()
	SetCVar("language.2","en")
end
 
function AdvancedLanguageSelector.OnAddOnLoaded(event, addonName)
  if addonName == AdvancedLanguageSelector.name then
    AdvancedLanguageSelector:Initialize()
  end
end

EVENT_MANAGER:RegisterForEvent(AdvancedLanguageSelector.name, EVENT_ADD_ON_LOADED, AdvancedLanguageSelector.OnAddOnLoaded)
  Reply With Quote
08/30/18, 10:02 AM   #2
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,800
Like written in your other post about it:

Add ReloadUI() after switiching the CVar in your function:
Lua Code:
  1. function AdvancedLanguageSelector:Initialize()
  2.     SetCVar("language.2","en")
  3.         ReloadUI()
  4. end

Without reloadui it will not rebuild the texts and use the game client's language texts.

Explanation:
The game texts are build AFTER login to the client so you see the texts in the addon list (if you are not logged in with a char -> at char selection) already.
If you do not change the language in the Launcher before it won't affect the game anymore.
Even changing the cvar via an adodn won't reload the UI so the texts get rebuild.
That's why you need to add the ReloadUI() call in your addon to force the game to reload the texts "now".

If you use the same command to change the cvar ingame as a script inside the chat, like
/script SetCVar("language.2","en")
the game will automatically do the reloadui for you. But addons behave in a different way if you change the cvars as some need, and many don't need a new reloaded UI.

Last edited by Baertram : 08/30/18 at 10:04 AM.
  Reply With Quote
08/30/18, 10:54 AM   #3
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
Originally Posted by Baertram View Post

The game texts are build AFTER login to the client so you see the texts in the addon list (if you are not logged in with a char -> at char selection) already.
That is fine for me. I would be absolutely happy if the texts would be "translated" after choosing my character, would that work?

Edit: Okay let's stay in this thread , I just read the other one and it seems like your suggested reloadui is exactly what I was looking for anyway. I will try it out.
  Reply With Quote
08/30/18, 10:57 AM   #4
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,800
No, as described above and in the other thread already 3 times now
Simply put the ReloadUI() in the function and you are set.

You won't even notice it as it's a constant loading of the addons as you are doing this uplon login only 1 time.
Just try it out. Your loading time will be twice as long as normal after login, depending on the amount of enabled addons you are using.

+all other addons will see that the language changed too and react on it properly then (at least if they get loaded after your addon).
  Reply With Quote
08/30/18, 11:02 AM   #5
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
Originally Posted by Baertram View Post
No, as described above and in the other thread already 3 times now
Simply put the ReloadUI() in the function and you are set.

You won't even notice it as it's a constant loading of the addons as you are doing this uplon login only 1 time.
Just try it out. Your loading time will be twice as long as normal after login, depending on the amount of enabled addons you are using.

+all other addons will see that the language changed too and react on it properly then (at least if they get loaded after your addon).
I added the ReloadUI() as advised and nothing changed. I still get this cripple.
  Reply With Quote
08/30/18, 11:12 AM   #6
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,800
Did you DISABLE all other addons and check if it is all English then?
The crit texts e.g. might come from other addons.
And other texts as well.

Please always test with all other addons disabled and if this works go on with other addons enabled.
Disable the adodns BEFORE login for your test character, at the char selection screen -> AddOns.

If this does not work, try the /script command in the chat and check if it looks ok afterwards.
If so it might be something else to do in your addon to achieve the same.

btw: There are language selector addons available, did you check their code? Are they using the same funcitons and ways?
Do they work properly if you use them? (without other addons enabled!)
  Reply With Quote
08/30/18, 11:31 AM   #7
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
Yes all addons disabled, same behaviour. As I said, adding the ReloadUI() had apparently no impact at all. However doing a /reloadui manually gives me exactly the result that I am looking for.

And no, I didn't check other codes because I am not a coder and I wouldn't be able to analyze them anyway. However I had a look on them and they were all not doing what I want to achieve either
  Reply With Quote
08/30/18, 11:38 AM   #8
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,800
Perhaps we need to do the reloadui later then after all other stuff was loaded and you are read for the game.
The event is the event_player_activated.

Try this:

Lua Code:
  1. AdvancedLanguageSelector = {}
  2. AdvancedLanguageSelector.name = "AdvancedLanguageSelector"
  3.  
  4. function AdvancedLanguageSelector:Initialize()
  5.     EVENT_MANAGER:RegisterForEvent(AdvancedLanguageSelector.name, EVENT_PLAYER_ACTIVATED, AdvancedLanguageSelector.OnPlayerActivated)
  6. end
  7.  
  8. function AdvancedLanguageSelector.OnPlayerActivated()
  9.     EVENT_MANAGER:UnregisterForEvent(AdvancedLanguageSelector.name, EVENT_PLAYER_ACTIVATED)
  10.     SetCVar("language.2","en")
  11.     ReloadUI()
  12. end
  13.  
  14. function AdvancedLanguageSelector.OnAddOnLoaded(event, addonName)
  15.     if addonName == AdvancedLanguageSelector.name then
  16.         AdvancedLanguageSelector:Initialize()
  17.     end
  18. end
  19.  
  20. EVENT_MANAGER:RegisterForEvent(AdvancedLanguageSelector.name, EVENT_ADD_ON_LOADED, AdvancedLanguageSelector.OnAddOnLoaded)
  Reply With Quote
08/30/18, 11:57 AM   #9
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
I tried this and all this gets me is an "infinite" loading screen.
Actually the loading screen looks like it's finished and then just restarts.
Is it possible that we created an infinite loop because the ReloadUI() will just infinitely execute?
  Reply With Quote
08/30/18, 12:07 PM   #10
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,800
Could be. Just remove the ReloadUI() command by putting -- in front of it and try again.
But normally the event_player_activated should only load once, and I've unregistered it too so it definately only loads once.

Is your addon's folder name and the name in the txt + the txt file name + lua filenam itsself definately this?
"AdvancedLanguageSelector"
e.g.
\live\AddOns\AdvancedLanguageSelector\
AdvancedLanguageSelector.txt
AdvancedLanguageSelector.lua

Inside the txt file
## Title: AdvancedLanguageSelector
## APIVersion: 100024

It needs to be the same like AdvancedLanguageSelector.name as your code is checking in the function OnAddonLoaded:

if addonName == AdvancedLanguageSelector.name then
...
end
  Reply With Quote
08/30/18, 12:22 PM   #11
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
Lol.
After excluding ReloadUI() the game does not only load again, but it's also fully translated into english. What the hell?
  Reply With Quote
08/30/18, 12:28 PM   #12
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,140
When you reload the UI, the Lua run time gets destroyed and loads again, including all events. Of course that will end in an endless reload loop. However, as far as I am aware setting the language cvar also implicitly runs an UI reload, so I am not sure if running reloadUI will even make any difference.

Two things you could try are running the SetCVar way early, simply in the first line of the lua file. That way it will be executed before pretty much anything.

If that doesn't work, you might want to try if the ReloadUI in event_player_activated really makes a difference. For that to work you need some extra code.
First you need to enabled saved variables in your addon. Simply add the following line in your manifest:
Code:
## SavedVariables: AdvancedLanguageSelector_Data
Then you extend the EVENT_PLAYER_ACTIVATED to look like this:

Lua Code:
  1. function AdvancedLanguageSelector.OnPlayerActivated(_, initial)
  2.     EVENT_MANAGER:UnregisterForEvent(AdvancedLanguageSelector.name, EVENT_PLAYER_ACTIVATED)
  3.     if(initial) then
  4.         AdvancedLanguageSelector_Data = {needsReload = true}
  5.         SetCVar("language.2","en")
  6.     elseif(AdvancedLanguageSelector_Data.needsReload) then
  7.         AdvancedLanguageSelector_Data.needsReload = false
  8.         ReloadUI()
  9.     end
  10. end
That way it will set the language when you log in and only reload once.
__________________
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
08/30/18, 12:33 PM   #13
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
Alright thanks.
Should I add this despite the fact that it seems to work now?
Also if running the SetCVar in the first line, does that mean that the .lua file is a 1 liner? Sorry if this question is stupid, I am new to this.


Edit: I tested it multiple times and the thing seems to work flawlessly now.
The code looks like this:
Lua Code:
  1. AdvancedLanguageSelector = {}
  2. AdvancedLanguageSelector.name = "AdvancedLanguageSelector"
  3.  
  4. function AdvancedLanguageSelector:Initialize()
  5.     EVENT_MANAGER:RegisterForEvent(AdvancedLanguageSelector.name, EVENT_PLAYER_ACTIVATED, AdvancedLanguageSelector.OnPlayerActivated)
  6. end
  7.  
  8. function AdvancedLanguageSelector.OnPlayerActivated()
  9.     EVENT_MANAGER:UnregisterForEvent(AdvancedLanguageSelector.name, EVENT_PLAYER_ACTIVATED)
  10.     SetCVar("language.2","en")
  11. end
  12.  
  13. function AdvancedLanguageSelector.OnAddOnLoaded(event, addonName)
  14.     if addonName == AdvancedLanguageSelector.name then
  15.         AdvancedLanguageSelector:Initialize()
  16.     end
  17. end
  18.  
  19. EVENT_MANAGER:RegisterForEvent(AdvancedLanguageSelector.name, EVENT_ADD_ON_LOADED, AdvancedLanguageSelector.OnAddOnLoaded)

Is this foolproof or is there anything else I need to change/check before uploading it?
(Yes I wanna upload it here to share my work with other people who might wanna play the game in the same way I do )

Thanks Baertram and sirinsidiator for your help!!

Last edited by lnfinity : 08/30/18 at 12:54 PM.
  Reply With Quote
08/30/18, 12:54 PM   #14
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,140
Yes, if you put it in the first line and it works, you won't need the other code.
__________________
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
08/30/18, 01:14 PM   #15
lnfinity
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 22
I tried the 1 liner solution and this only gets me back to the "crippled" translation.
Seems like I will stick with the solution that works (for some reason which I don't understand).
  Reply With Quote
08/30/18, 02:28 PM   #16
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,800
Not sure if this is correct but an attempt to explain:

Event_addon_loaded fires before the UI is loaded, or sort of at least.
It fires for each addon, that is why you compare the addonName in the callback function with your addon name! Else your code would run on EVERY single addon that loads the event
At this point there might have been missing texts which got loaded after your addon on the time axis and thus some where loaded and translated, others weren't.

event_player_activated is a bit later in the call chain, and fires as your char is loaded and ready to move in the world. It also fires after a zone change or wayshrine teleport etc.
So maybe the crippled text was because your changes were too early, and not too late.
As the event_player_activated fired the Ui was loaded and all texts are there, then your code changes the language and the texts are exchanged properly.

Last edited by Baertram : 08/30/18 at 02:31 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How to make my addon load earlier?

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