I have been trying to make a ingame GUI with Ace3 I had all code in one file and the options in my config file. I wanted to have my code split into modules. I am not sure how to do this 100%. Right now I got it to show up but when I go to select a option in the GUI I get a error.
Error:
Message: Interface\AddOns\DreamTweaks\Config.lua:46: attempt to call global 'ActionBars' (a nil value)
Time: 09/05/11 00:19:08
Count: 1
Stack: Interface\AddOns\DreamTweaks\Config.lua:46: in function <Interface\AddOns\DreamTweaks\Config.lua:44>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[2]"]:9: in function <[string "safecall Dispatcher[2]"]:5>
(tail call): ?
...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:798: in function <...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:613>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[3]"]:9: in function <[string "safecall Dispatcher[3]"]:5>
(tail call): ?
...ce\AddOns\DreamTweaks\Libs\AceGUI-3.0\AceGUI-3.0.lua:314: in function `Fire'
...ks\Libs\AceGUI-3.0\widgets\AceGUIWidget-CheckBox.lua:68: in function <...ks\Libs\AceGUI-3.0\widgets\AceGUIWidget-CheckBox.lua:57>
Locals: <none>
Modules/ActionBars.lua
local DreamTweaks = LibStub("AceAddon-3.0"):GetAddon("DreamTweaks")
local ActionBars= DreamTweaks:NewModule("ActionBars")
local db;
function ActionBars:OnEnable()
if db.HideGryphons then
MainMenuBarLeftEndCap:Hide()
MainMenuBarRightEndCap:Hide()
else
MainMenuBarLeftEndCap:Show()
MainMenuBarRightEndCap:Show()
end
end
function ActionBars:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("DreamTweaksDB", defaults, "Default");
db = self.db.profile;
end
Core.lua
local DreamTweaks = LibStub("AceAddon-3.0"):NewAddon("DreamTweaks", "AceConsole-3.0", "AceEvent-3.0");
local db;
local _G = _G
local defaults = {
profile = {
HideGryphons = false,
},
};
function DreamTweaks:Refresh()
db = self.db.profile;
self:ConfigRefresh();
end
function DreamTweaks:PLAYER_LOGIN()
self:Refresh();
end
function DreamTweaks:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("DreamTweaksDB", defaults, "Default");
self.db.RegisterCallback(self, "OnProfileChanged", "Refresh");
self.db.RegisterCallback(self, "OnProfileCopied", "Refresh");
self.db.RegisterCallback(self, "OnProfileReset", "Refresh");
self:SetUpOptions();
db = self.db.profile;
SLASH_RELOAD1 = '/rl'
SlashCmdList.RELOAD = ReloadUI
self:RegisterEvent("PLAYER_LOGIN");
end
Config.lua
local DreamTweaks = LibStub("AceAddon-3.0"):GetAddon("DreamTweaks");
local db;
local options = nil;
local function GetOptions()
if not options then
options = {
type = "group",
name = "DreamTweaks",
handler = DreamTweaks,
childGroups = "tab",
args = {
ActionBars = {
name = "ActionBars",
type = "group",
order = 1,
args = {
HideGryphons = {
name = "HideEndCaps",
type = "toggle",
order = 1,
set = function(info, val)
db.HideGryphons = val
ActionBars()
end,
get = function(info) return db.HideGryphons end,
},
},
},
},
};
end
return options
end
function DreamTweaks:ChatCommand(input)
InterfaceOptionsFrame_OpenToCategory(self.profilesFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
InterfaceOptionsFrame:Raise()
end
function DreamTweaks:ConfigRefresh()
db = self.db.profile;
end
function DreamTweaks:SetUpOptions()
db = self.db.profile;
LibStub("AceConfig-3.0"):RegisterOptionsTable("DreamTweaks", GetOptions);
LibStub("AceConfig-3.0"):RegisterOptionsTable("DreamTweaks-Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db));
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("DreamTweaks", "DreamTweaks");
self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("DreamTweaks-Profiles", "Profiles", "DreamTweaks");
self:RegisterChatCommand("DT", "ChatCommand");
end
There is much more code but to long to post all of it so I just posted what I thought would be needed to help me.
As the error message states, on line 46 in Config.lua you attempt to call this function:
ActionBars()
... which does not exist in the global namespace (or in any local namespace in any of the code you posted). I think you were probably going for something like this:
Your are creating your addon database again in your module :
function ActionBars:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("DreamTweaksDB", defaults, "Default");
It will propably cause issues (by the way, use true instead of "Default" as the third parameter, it is locale-safe). Simply use something like this to fetch the database of the core :
function ActionBars:OnInitialize()
self.db = DreamTweaks.db
Moreover, calling ActionBars:Enable() won't call ActionBars:OnEnable() again if the module is already enabled. You should move the code to some other methods (like :ApplyConfig) and call this from ActionBars:OnEnable and from the option handler (instead of your initial ActionBars()).
e.g.:
function ActionBars:OnEnable()
self:ApplyConfig()
end
function ActionBars:ApplyConfig()
db = self.db.profile
if db.HideGryphons then
MainMenuBarLeftEndCap:Hide()
MainMenuBarRightEndCap:Hide()
else
MainMenuBarLeftEndCap:Show()
MainMenuBarRightEndCap:Show()
end
end
And in the option handler:
set = function(info, val)
db.HideGryphons = val
DreamTweaks:GetModule("ActionBars"):ApplyConfig()
end,
One of these days I will understand all this. I have only working with Ace3 for 2 weeks, It's so alien to me. Then again I have not been coding for very long and been teaching my self with the help of other addon creators.
O one other question. How can I put a option to enable or disable the module and if disabled the options in the ingame GUI don't show? Is this possible to do?
This is a good resource for learning how to use AceConfig. As you can see, there is a common parameter "hidden" which can take a function. So something like:
ActionBars = {
name = "ActionBars",
type = "group",
hidden = function() return not db.ModuleActionBars end,
...
}
And then you can make a toggle to turn on/off db.ModuleActionBars.
function ActionBars:ApplyConfig()
if self.db.profile.ActionBars.Enable then
--more code
else
if not self.db.profile.ActionBars.Enable then return end
end
To enable and disable the whole module, you could have something like this in options.lua :
ActionBars = {
name = "ActionBars",
type = "group",
order = 1,
args = {
Enable={
name="Enable",
desc="Enables / disables the addon",
type="toggle",
order = 1,
set = function(info, val)
db.ActionBars.Enable = val
if val then
DreamTweaks:EnableModule("ActionBars")
else
DreamTweaks:DisableModule("ActionBars")
end
end,
get = function(info) return db.ActionBars.Enable end,
},
OtherOption = {
-- ...
hidden = function(info) return not db.ActionBars.Enable end,
},
},
You have to ensure that the OnEnable and OnDisable methods of your module properly apply/revert the changes (probably by calling ApplyConfig). Moreover, the OnInitialize method should use db.ActionBars.Enable to set the initial state:
function ActionBars:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("DreamTweaksDB", defaults, "Default");
db = self.db.profile;
-- Do not automatically enable the addon if disabled in config
self:SetEnabledState(db.ActionBars.Enable)
end
function ActionBars:OnDisable()
self:ApplyConfig()
end
Dos the "if not then return end" not work for action bar modules with Ace3?
I did what you said and still it will set my module if enabled but if I disable it it dos nothing till I do a reload.
ActionBars = {
name = "ActionBars",
type = "group",
order = 1,
args = {
Enable={
name="Enable",
desc="Enables / disables the addon",
type="toggle",
order = 1,
set = function(info, val)
db.ActionBars.Enable = val
if val then
DreamTweaks:EnableModule("ActionBars")
else
DreamTweaks:DisableModule("ActionBars")
end
end,
get = function(info) return db.ActionBars.Enable end,
},
function ActionBars:OnEnable()
self:ApplyConfig()
end
function ActionBars:ApplyConfig()
db = self.db.profile
--more code
if not self.db.profile.ActionBars.Enable == true then return end
end
function ActionBars:Refresh()
db = self.db.profile
self:ApplyConfig()
end
function ActionBars:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("DreamTweaksDB", defaults, "Default");
db = self.db.profile;
-- Do not automatically enable the addon if disabled in config
self:SetEnabledState(self.db.profile.ActionBars.Enable)
self.db = DreamTweaks.db
self.db.RegisterCallback(self,"OnProfileChanged","Refresh")
self.db.RegisterCallback(self,"OnProfileCopied","Refresh")
self.db.RegisterCallback(self,"OnProfileReset","Refresh")
end
function ActionBars:OnDisable()
self:ApplyConfig()
end
Enable={
name="Enable",
desc="Enables / disables the addon",
type="toggle",
order = 1,
set = function(info, val)
db.ActionBars.Enable = not db.ActionBars.Enable
if db.ActionBars.Enable then
DreamTweaks:EnableModule("ActionBars")
else
DreamTweaks:DisableModule("ActionBars")
end
end,
get = function(info) return db.ActionBars.Enable end,
},
You are probably still doing bad things with the addon database since you are overwriting it in your module. Fix this :
function ActionBars:OnInitialize()
[COLOR="Red"][STRiKE]self.db = LibStub("AceDB-3.0"):New("DreamTweaksDB", defaults, "Default");[/STRIKE][/COLOR]
[COLOR="Green"]self.db = DreamTweaks.db[/color]
db = self.db.profile;
-- Do not automatically enable the addon if disabled in config
self:SetEnabledState(db.ActionBars.Enable)
self.db.RegisterCallback(self,"OnProfileChanged","Refresh")
self.db.RegisterCallback(self,"OnProfileCopied","Refresh")
self.db.RegisterCallback(self,"OnProfileReset","Refresh")
end
Errrg getting so frustrated with myself. I can't figure this stuff out.
"Torhal" I tried your suggestion and still same thing I have to do a reload if I deselect the enable box in the GUI. But if it is disabled and I turn it on it dos it with no reload.
"Adirelle" I changed that part of the code to. I see no difference but who knows (I don't).
Add some print statements in "OnInitialize", "OnEnable", "OnDisable" and "ApplyConfig" to see what is called (and what is the value of the setting) ; it might help you. You are probably having issue not with the module but with your options.
Add some print statements in "OnInitialize", "OnEnable", "OnDisable" and "ApplyConfig" to see what is called (and what is the value of the setting) ; it might help you. You are probably having issue not with the module but with your options.
Ok sorry for being such a Nub. But what do I have it say, look for. In other words how do I do the print?
In my original post, I should have mentioned you can also just add whatever stuff you want to know, in it
function ActionBars:OnInitialize()
self.db = DreamTweaks.db
db = self.db.profile;
print("Hello OnInitialize!", [COLOR="Red"]db.ActionBars.Enable[/COLOR])
-- do stuff
end
function ActionBars:OnInitialize()
self.db = DreamTweaks.db
db = self.db.profile;
print("Hello OnInitialize!", [COLOR="Red"]db.ActionBars.Enable[/COLOR])
-- do stuff
end
Nothing shows in chat, but I get this error.
Message: Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:231: attempt to index upvalue 'db' (a nil value)
Time: 09/07/11 22:15:52
Count: 1
Stack: Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:231: in function <Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:230>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
...ddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:514: in function `InitializeAddon'
...ddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:628: in function <...ddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:621>
Locals: self = <table> {
SetDefaultModuleLibraries = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:383
Enable = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:315
NewModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:256
EnableModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:348
modules = <table> {
}
GetModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:231
IterateEmbeds = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:458
IsModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:238
baseName = "DreamTweaks"
defaultModuleLibraries = <table> {
}
OnDisable = <function> defined @Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:244
OnInitialize = <function> defined @Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:230
SetEnabledState = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:440
moduleName = "ActionBars"
enabledState = true
ApplyConfig = <function> defined @Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:34
OnEnable = <function> defined @Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:28
Refresh = <function> defined @Interface\AddOns\DreamTweaks\Modules\ActionBars.lua:225
GetName = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:300
defaultModuleState = true
Disable = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:330
IterateModules = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:453
name = "DreamTweaks_ActionBars"
SetDefaultModulePrototype = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:425
IsEnabled = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:467
orderedModules = <table> {
}
SetDefaultModuleState = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:403
DisableModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:366
}
(*temporary) = <function> defined @Interface\FrameXML\RestrictedInfrastructure.lua:116
(*temporary) = "Hello OnInitialize!"
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index upvalue 'db' (a nil value)"
db = nil
DreamTweaks = <table> {
SetDefaultModuleLibraries = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:383
Enable = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:315
RegisterChatCommand = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceConsole-3.0\AceConsole-3.0.lua:85
EnableModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:348
modules = <table> {
}
GetModule = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:231
IterateEmbeds = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceAddon-3.0\AceAddon-3.0.lua:458
defaultModuleLibraries = <table> {
}
optionsFrame = <unnamed> {
}
UnregisterChatCommand = <function> defined @Interface\AddOns\DreamTweaks\Libs\AceConsole-3.0\AceConsole-3.0.l
Error:
Modules/ActionBars.lua
Core.lua
Config.lua
There is much more code but to long to post all of it so I just posted what I thought would be needed to help me.
... which does not exist in the global namespace (or in any local namespace in any of the code you posted). I think you were probably going for something like this:
Um. I realy don't know. I'm very new to this. Ok I entered
in place of the
in the options. It dos not give me a error anymore but it dos not change anything also.
It will propably cause issues (by the way, use true instead of "Default" as the third parameter, it is locale-safe). Simply use something like this to fetch the database of the core :
Moreover, calling ActionBars:Enable() won't call ActionBars:OnEnable() again if the module is already enabled. You should move the code to some other methods (like :ApplyConfig) and call this from ActionBars:OnEnable and from the option handler (instead of your initial ActionBars()).
e.g.:
And in the option handler:
One of these days I will understand all this. I have only working with Ace3 for 2 weeks, It's so alien to me. Then again I have not been coding for very long and been teaching my self with the help of other addon creators.
This is a good resource for learning how to use AceConfig. As you can see, there is a common parameter "hidden" which can take a function. So something like:
And then you can make a toggle to turn on/off db.ModuleActionBars.
You have to ensure that the OnEnable and OnDisable methods of your module properly apply/revert the changes (probably by calling ApplyConfig). Moreover, the OnInitialize method should use db.ActionBars.Enable to set the initial state:
I did what you said and still it will set my module if enabled but if I disable it it dos nothing till I do a reload.
"Torhal" I tried your suggestion and still same thing I have to do a reload if I deselect the enable box in the GUI. But if it is disabled and I turn it on it dos it with no reload.
"Adirelle" I changed that part of the code to. I see no difference but who knows (I don't).
Ok sorry for being such a Nub. But what do I have it say, look for. In other words how do I do the print?
http://www.lua.org/manual/5.1/manual.html#pdf-print
http://www.wowpedia.org/API_print
-- EDIT:
In my original post, I should have mentioned you can also just add whatever stuff you want to know, in it
All show up in the chat frame but the "OnDisable".
So the module is never disabled.
Add some print("db.ActionBars.Enable=", db.ActionBars.Enable) in various places, including the configuration get and set functions.
All is coming up nil,nil,nil but nothing on the "OnDisable".
Nothing shows in chat, but I get this error.
Same nothing shows in chat but I get this error.