Thread Tools Display Modes
03/22/16, 10:49 AM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
SetSettings issue

In my addon ScreenshotHelper I try to disable all UI elements that are not hidden with the hide interface shortcut. In order to achieve this, I use SetSetting to turn off a couple of things.

This works most of the time, but sometimes it just randomly doesn't and the worst part, it doesn't fail consistently. It seems to only happen after login and only with settings that have a boolean value (checkboxes). Sometimes the group indicators just stay off, another time it is the FPS widget that gets disabled. I have yet to find a reason or a pattern why these stay off and other than that I am all out of ideas. Maybe someone can shed some light on the issue?

The code in question looks like this and for the full code, just download the addon.
lua Code:
  1. -- the settings we want to overwrite when the gui gets hidden
  2. local DESIRED_SETTINGS = {
  3.     [SETTING_TYPE_UI] = {
  4.         [UI_SETTING_SHOW_QUEST_BESTOWER_INDICATORS] = false,
  5.         [UI_SETTING_SHOW_FRAMERATE] = false,
  6.         [UI_SETTING_SHOW_LATENCY] = false,
  7.     },
  8.     [SETTING_TYPE_NAMEPLATES] = {
  9.         [NAMEPLATE_TYPE_ALL_HEALTHBARS] = false,
  10.         [NAMEPLATE_TYPE_ALLIANCE_INDICATORS] = NAMEPLATE_CHOICE_OFF,
  11.         [NAMEPLATE_TYPE_GROUP_INDICATORS] = false,
  12.         [NAMEPLATE_TYPE_RESURRECT_INDICATORS] = false,
  13.         [NAMEPLATE_TYPE_FOLLOWER_INDICATORS] = false,
  14.     },
  15.     [SETTING_TYPE_COMBAT] = {
  16.         [COMBAT_SETTING_SCROLLING_COMBAT_TEXT_ENABLED] = false,
  17.     },
  18.     [SETTING_TYPE_CHAT_BUBBLE] = {
  19.         [CHAT_BUBBLE_SETTING_ENABLED] = false,
  20.     },
  21.     [SETTING_TYPE_IN_WORLD] = {
  22.         [IN_WORLD_UI_SETTING_TARGET_GLOW_ENABLED] = false,
  23.         [IN_WORLD_UI_SETTING_INTERACTABLE_GLOW_ENABLED] = false,
  24.     }
  25. }
  26. -- we copy the structure to a second table where we save the current values
  27. local savedSettings = ZO_DeepTableCopy(DESIRED_SETTINGS)
  28.  
  29. local function SaveSettings()
  30.     for system, entry in pairs(savedSettings) do
  31.         for settingId, value in pairs(entry) do -- for each setting in our structure we get the value either as a boolean or a number
  32.             if(type(value) == "boolean") then
  33.                 savedSettings[system][settingId] = GetSetting_Bool(system, settingId)
  34.             else
  35.                 savedSettings[system][settingId] = tonumber(GetSetting(system, settingId))
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. local function ApplyCustomSettings(settings)
  42.     for system, entry in pairs(settings) do
  43.         for settingId, value in pairs(entry) do
  44.             SetSetting(system, settingId, tostring(value)) -- we set each setting as a string
  45.         end
  46.     end
  47.     ApplySettings() -- call apply afterwards (no idea if this does anything)
  48. end
  49.  
  50. local function OnGuiHidden(eventcode, guiName, hidden)
  51.     if (guiName ~= INGAME_GUI_NAME) then return end
  52.     if (hidden) then -- when the gui gets hidden
  53.         SaveSettings()
  54.         ApplyCustomSettings(DESIRED_SETTINGS)
  55.         SetFloatingMarkerGlobalAlpha(0)
  56.     else -- when it becomes visible again
  57.         ApplyCustomSettings(savedSettings)
  58.         SetFloatingMarkerGlobalAlpha(1)
  59.     end
  60. end
  61.  
  62. local handle
  63. handle = RegisterForEvent(EVENT_PLAYER_ACTIVATED, function()
  64.     UnregisterForEvent(EVENT_PLAYER_ACTIVATED, handle)
  65.     SaveSettings() -- we save them once, in case the EVENT_GUI_HIDDEN is called with hidden == false for some reason
  66.     RegisterForEvent(EVENT_GUI_HIDDEN, OnGuiHidden)
  67. end)
  Reply With Quote
04/28/16, 03:58 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I am still trying to figure out this problem.
I found a way to reliably reproduce it and either it is a bug in the game, or I am simply doing something wrong.
Here is a video which shows what I mean:

When I toggle GUI, the addon disables all options that are related to things that show up even when the GUI is hidden, like nameplates, sct, etc.
At this point everything is still okay.
Once I leave the area the settings are suddenly randomly discarded. It's always a different bunch of options that is disabled, but always the ones I have set to off and then on again.
  Reply With Quote
04/28/16, 04:10 PM   #3
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Did you try printing messages to see if your functions are called at unexpected times?

Also, I had the same doubts about 'ApplySettings()' and if it actually did something, until I had problems when changing the UI global scale. It only got applied after the aforementioned function has been invoked.

I can't right now, but later I'll check out some stock code that meddle with settings and see if I can figure something out.
  Reply With Quote
04/28/16, 04:47 PM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
The output is what you see in the top right corner.

I tried everything I can think off. Calling ApplySettings after every single SetSetting, once after everything was set, with a delay. I even called each SetSetting with some milliseconds delay between each. That's just a few things I tried, but nothing works.
  Reply With Quote
04/29/16, 09:56 AM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I looked around a bit more and saw that I used an incorrect value for setting NAMEPLATE_TYPE_ALLIANCE_INDICATORS. After I changed it, the behavior changed and it now always sets NAMEPLATE_TYPE_ALL_HEALTHBARS to off without fail. No other setting is affected. When I remove NAMEPLATE_TYPE_ALL_HEALTHBARS from the list, suddenly some other settings are affected again.
It feels like the game "light off" at this point.

I also saw that ApplySettings is only necessary when setting some of the video settings.
  Reply With Quote
04/29/16, 10:29 AM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I added this code which seems to solve the problem. Not really happy with it, but at least it seems to work now.
Lua Code:
  1. SaveSettings() -- save and restore the settings when we leave an area through a loading screen, otherwise they may get messed up
  2.     RegisterForEvent(EVENT_PLAYER_ACTIVATED, function()
  3.         if(not GetGuiHidden(INGAME_GUI_NAME)) then
  4.             ApplyCustomSettings(savedSettings)
  5.         else
  6.             ApplyCustomSettings(DESIRED_SETTINGS)
  7.         end
  8.     end)
  9.     RegisterForEvent(EVENT_PLAYER_DEACTIVATED, function()
  10.         if(not GetGuiHidden(INGAME_GUI_NAME)) then
  11.             SaveSettings()
  12.         end
  13.     end)
  Reply With Quote
04/30/16, 08:13 AM   #7
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Logged in on the pts and had half the settings switched to off again. Seems like the "fix" only helps with part of the problem. Guess I'll have to save the settings in saved variables and overwrite them whenever I log in...
  Reply With Quote
04/30/16, 10:39 AM   #8
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
OPTIONS_WINDOW_FRAGMENT calls RefreshSettings when showing, and SendAllCachedSettingMessages when hiding. Maybe you need to call those as well as ApplySettings.
  Reply With Quote
04/30/16, 12:04 PM   #9
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I just tried calling both ApplySettings and SendAllCachedSettingMessages immediately after setting them and in a second attempt on EVENT_PLAYER_DEACTIVATED, but it does not change anything.
Maybe @ZOS_ChipHilseberg has some input? The workaround I put in the latest version does seem to work for me, but I honestly would prefer if I could do it correctly and don't have to rely on something like that.
  Reply With Quote
05/02/16, 07:59 AM   #10
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
Can you summarize the repro steps for this? From what I read it looks like it's changing the settings and then going to another zone? We can look into it once we know exactly what we're looking for.
  Reply With Quote
05/02/16, 08:32 AM   #11
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Sure.
1) Install ScreenshotHelper v1.3.3
2) Bind the control for toggling the GUI (part of the base game's own controls)
3) Press the key twice
4) Either log out or go to a different area like in the video

What I do in the addon is calling SetSetting in a loop for all things that still show up when the interface is hidden. It works fine when I press the key, but breaks on step 4.
When the game crashes, it seems to keep the settings like expected.
  Reply With Quote
05/02/16, 08:48 AM   #12
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
What are the expected and observed result?

Also, here is how the settings system works. When a setting is changed it is cached off in a map on the client side. Every 1.5 seconds the client will pick a setting out of the map and send it to the server. This is done to prevent hitting the message rate limit when the player is quickly rotating through settings (like holding left on the thumb stick in the gamepad options for a horizontal list selector). The cache can be flushed manually by calling SendAllCachedSettingMessages() and it is also flushed automatically when the player changes zones or logs off. However, if it sends so many options updates that the message rate limit is hit, some of them can be lost.

ApplySettings() exists because some options changes (like graphics settings) are very disruptive when they are changed, sometimes requiring a reload. So they don't get put into effect until apply is called. I don't think this is your issue though.
  Reply With Quote
05/02/16, 10:29 AM   #13
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
The expected results is that the settings stay the same before and after the UI is toggled off and on again as this is only a temporary state for taking a screenshot without glows, nameplates etc.

The observed result is that they do stay the same when toggling off and on again, but after relogging or changing the area, part of the settings are falsely set to off.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » SetSettings issue


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