View Single Post
08/30/18, 12:28 PM   #12
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
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.
  Reply With Quote