deselectOnClick CVAR?

I have an addon that toggles the CVAR deselectOnClick when I go into combat (to prevent me from accidently clicking off the target) and toggles it back on when I’m done. I just noticed today (not sure when it actually broke to be honest) that I can no longer toggle this variable (in or out of combat). I can change it via the Sticky Targeting selection in settings, but no matter what I can’t seem to toggle it period via SetCVar()… I even checked with GetCVarInfo and it’s not locked, so not sure why I can’t.

This is my code which was working back in DF for sure. I have even tried just to toggle the CVar with all addons disabled. Still doesn’t work.

local function toggleSticky(self, event, ...)
  local value = (event == "PLAYER_REGEN_DISABLED" and "0" or "1")
  C_CVar.SetCVar("deselectOnClick", value)
  print("StickyTarget: toggled deselectOnClick to " .. value)
  print("StickyTarget: deselectOnClick set to " .. C_CVar.GetCVar("deselectOnClick"))
end
local f = CreateFrame("Frame", "StickyTargetListenerFrame", UIParent)
f:SetScript("OnEvent", toggleSticky)
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:RegisterEvent("PLAYER_REGEN_DISABLED")
print("StickTarget: Loaded")

Just for giggles, I tried modifying this to adjust the Sound_MasterVolume CVAR instead of deselectOnClick, and it works just fine. It’s something specifically with deselectOnClick.

And if you check both with C_CVar.GetCVarInfo() neither indicate that they can’t be altered. shrugs, out of ideas here.

local function toggleSticky(self, event, ...)
  local value = false
  if event == "PLAYER_REGEN_DISABLED" then
  	value = true
  end
  Settings.SetValue("deselectOnClick", value)
  local bool = value and "True" or "False"
  print("StickyTarget: toggled deselectOnClick to " .. bool)
  print("StickyTarget: deselectOnClick set to " .. C_CVar.GetCVar("deselectOnClick"))
end
local f = CreateFrame("Frame", "StickyTargetListenerFrame", UIParent)
f:SetScript("OnEvent", toggleSticky)
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:RegisterEvent("PLAYER_REGEN_DISABLED")
print("StickTarget: Loaded")

THANK YOU!

It works. I can’t seem to locate anything in regards to when I would use Settings.SetValue vs SetCVar (as ultimately the setting is still a CVar as I can edit it in config-cache.wtf and it stick). Funny enough Blizzard even has a line in their own code (Interface/AddOns/Blizzard_Commentator/Blizzard_Commentator.lua) that is still doing a SetCVar on this exact setting.

We are not Blizzard… or commentators. Well, not that sort of commentator :wink:

That’s for sure, I actually don’t even know what that addon for. Thanks again for the help, these random undocumented changes are always about as clear as mud.