Thread Tools Display Modes
01/27/17, 02:31 PM   #1
Hoft
 
Hoft's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 17
Menu getFunc

I have a problem with simple code ((
My menu allways show only default value!
setFunc works right and changes variable
ZO_SavedVars works right and load/saves variable
When I change variable by menu, key bind, slash command, or any other way and returns to menu… it allways show default value! Where is my mistake?

Code:
Addon = {
	name = "Addon",
	Menu = {},
	Vars = {},
	Defaults = {
		["OnOff"] = true,
	}
};

function Addon.Menu()
	local options = {
		{	type	= "header",
			name	= "Options",
			width	= "full"
		},
		{	type	= "checkbox",
			name	= "Enables add-on",
			tooltip	= "",
			getFunc	= function() return Addon.Vars.OnOff end,
			setFunc	= function(value) Addon.Vars.OnOff =value end,
			default	= Addon.Defaults.OnOff,
		},
	local menu = LibStub("LibAddonMenu-2.0")
	local panel = {
		type = "panel",
		name = "Add-on",
		displayName = "Add-on",
		author = "autor",
		version = "1",
	}
	menu:RegisterAddonPanel("AddonMenu", panel)
	menu:RegisterOptionControls("AddonMenu", options)
end

function Addon.OnAddOnLoaded( eventCode, addonName )
	if (addonName ~= Addon.name) then return end

	EVENT_MANAGER:UnregisterForEvent(Addon.name, EVENT_ADD_ON_LOADED)

	Addon.Vars = ZO_SavedVars:NewAccountWide( "Addon_Settings" , version , nil , Addon.Defaults )
	Addon.Menu()
end

Last edited by Hoft : 01/27/17 at 02:35 PM.
  Reply With Quote
01/27/17, 02:43 PM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
version is nil?
should be a number, e.g. 1.
  Reply With Quote
01/29/17, 01:55 AM   #3
Hoft
 
Hoft's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 17
Originally Posted by votan View Post
version is nil?
should be a number, e.g. 1.
Right! Just forgotted to place this variable in example.
But version is assigned in my version of the add-on.

Nearly solved: ZOS bug? getFunc can receive only local variables! Now it works:

Code:
function Addon.Menu()
	local settings=Addon.Vars
	local options = {
		{	type	= "checkbox",
			name	= "Enables add-on",
			tooltip	= "",
			getFunc	= function() return settings.OnOff end,
			setFunc	= function(value) Addon.Vars.OnOff =value end,
			default	= Addon.Defaults.OnOff,
		},
end
But now ZO_SavedVars do not saves actual values!
  Reply With Quote
01/29/17, 02:35 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Hoft View Post
I have a problem with simple code ((
My menu allways show only default value!
setFunc works right and changes variable
ZO_SavedVars works right and load/saves variable
When I change variable by menu, key bind, slash command, or any other way and returns to menu… it allways show default value! Where is my mistake?
The problem is not directly with your code.
Addon is a global variable and "Addon_Settings" is not really a unique name. If you have to save Addon.Vars to a local variable, you have a global variable conflict.
Somebody else is using Addon as a global variable. Make Addon local.
  Reply With Quote
01/29/17, 04:32 PM   #5
Hoft
 
Hoft's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 17
Name «Addon» I used only in this exapmle
  Reply With Quote
01/29/17, 05:34 PM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Please post the code with the names etc. that is not working and not some "placeholders".
It's easier to check it then.

From what I can see so far there shouldn't be any problem with your code if you use a global "unique" addon name.
There shouldn't be any reason to locally re-assign your global addon variables then just so the addon saves them.

Do you have applied the "SavedVariables" name in your manifest txt file of the addon? It must be the same name that you use in your addon: Addon_Settings
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Menu getFunc

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