This will probably be the first of many questions, since I'm a novice programmer trying to create an AddOn. ^^
Do note that I have looked at the tutorials, but I can't find any good example code to help me with the issue I've run into.
I'm trying to create an options GUI for my AddOn, according to the tutorials this should work via AceConfigDialog-3.0. The piece of code from said tutorial does not seem to work though, probably because I'm using it wrong. ^^
What it should do: Add my AddOn into the Interface Options panel and create a Profiles subcategory. It's also supposed to open the Options GUI by using /tql and save the settings, though my primary problem is getting an Options GUI. :p
What happens in stead: I get the following Lua error:
Interface\AddOns\Tql\Tql.lua:42: attempt to index global 'self' (a nil value)
Tql.toc
## Interface: 40000
## Title: Tag's Quest Log
## Notes: Enhances the Quest Log and Tracker.
## Author: Tag of Fire
## Version: v0.1
## SavedVariables: TqlDB
libs\LibStub\LibStub.lua
libs\CallbackHandler-1.0\CallbackHandler-1.0.xml
libs\AceAddon-3.0\AceAddon-3.0.xml
libs\AceGUI-3.0\AceGUI-3.0.xml
libs\AceConfig-3.0\AceConfig-3.0.xml
libs\AceConsole-3.0\AceConsole-3.0.xml
libs\AceDB-3.0\AceDB-3.0.xml
libs\AceDBOptions-3.0\AceDBOptions-3.0.xml
libs\AceHook-3.0\AceHook-3.0.xml
libs\AceEvent-3.0\AceEvent-3.0.xml
libs\AceTimer-3.0\AceTimer-3.0.xml
libs\AceLocale-3.0\AceLocale-3.0.xml
libs\LibQuixote-2.0\lib.xml
libs\AceGUI-3.0-SharedMediaWidgets\widget.xml
libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
Tql.lua
General.lua
QuestLog.lua
QuestTracker.lua
Tql.lua
Tql = LibStub("AceAddon-3.0"):NewAddon("Tag's Quest Log", "AceConsole-3.0")
local options = {
name = "Tag's Quest Log",
handler = Tql,
type = 'group',
args = {
msg = {
type = 'input',
name = 'My Message',
desc = 'The message for my addon',
set = 'SetMyMessage',
get = 'GetMyMessage',
},
},
}
function Tql:OnInitialize()
Tql:RegisterChatCommand("tql", "TqlSlash")
self.db = LibStub("AceDB-3.0"):New("Tag's Quest Log", self.defaults, "Default")
self.profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
end
function Tql:OnEnable()
end
function Tql:OnDisable()
end
function Tql:TqlSlash(input)
InterfaceOptionsFrame_OpenToCategory("Tag's Quest Log")
end
LibStub("AceConfig-3.0"):RegisterOptionsTable("TqlProfiles", self.profileOptions)
self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TqlProfiles", "Profiles", "Tag's Quest Log")
I think I'm also forgetting to register the main options besides adding the Profiles, but I'm kind of lost right now and can't figure it out at all. :(
Could anyone provide me with or tell me where to find a piece of example code I can work from, or show me where I went wrong with this piece of code? <:
"self" is a special local variable inside of a function invoked via the "table:function()" paradigm. it is assigned to be equal to the "table" portion of the function call. in code:
function myAddon:myFunction(arg1,arg2)
...
end
is the same as:
function myAddon.myFunction(self, arg1, arg2)
...
end
and
local x = myAddon:myFunction(a,b)
is equivalent to:
local x = myAddon.myFunction(myAddon, a,b)
so basically, "self" is only valid inside of a function defined via the table:function method unless it's explicitly defined.
you have two "self" references are outside of a function, so they're just normal variable references. since you don't define "self" as a local anywhere, it's looking for a global named self which doesn't exist.
judging by your code, you should probably substitute the "Tql" table in place of the "self" reference in your final two lines.
You need to register your options table before you can do anything with it. You should also put your profile options into your main options table, unless you're planning to do something else with it.
function Tql:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("Tag's Quest Log", self.defaults, "Default")
options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfig-Registry-3.0"):RegisterOptionsTable("Tql", options)
self:RegisterChatCommand("tql", "TqlSlash")
end
Thanks to the both of you, I now understand my code a bit better -and- I was able to properly register my config into the Interface Options frame. ^^
I was planning on slowly starting to make the config UI itself, but figured it would be best if I made some example options first and make sure my SavedVariables, default settings and Profiles work properly.
As you can guess, they dont. :p
No settings are saved through reloads, nor do the profiles seem to work.
- I think I might not have defined the local defaults properly.
- I think I'm not loading them properly, either.
- I think I haven't 'linked' my SavedVariables to my Profiles.. or something along those lines.
- I have a feeling I'm forgetting something else that I need to make my SavedVariables, profiles and Default profile work properly as well. :p
Here is once again, my Tql.xml code:
Tql = LibStub("AceAddon-3.0"):NewAddon("Tag's Quest Log", "AceConsole-3.0")
-- The configurable options.
local options = {
name = "Tag's Quest Log",
handler = TqlOptions,
type = 'group',
args = {
general = {
type = 'group',
name = "Tag's Quest Log",
args = {
enable = {
name = "Enable AddOn",
desc = "Enables the AddOn.",
type = "toggle",
set = function(info,val) Tql.enabled = val end,
get = function(info) return Tql.enabled end
},
},
},
log = {
type = 'group',
name = "Tag's Quest Log",
args = {
blah1 = {
name = "Some Log option",
desc = "Does something. =D",
type = "toggle",
set = function(info,val) Tql.blah1 = val end,
get = function(info) return Tql.blah1 end
},
},
},
tracker = {
type = 'group',
name = "Tag's Quest Log",
args = {
blah2 = {
name = "Some Tracker option",
desc = "Does something. =D",
type = "toggle",
set = function(info,val) Tql.blah2 = val end,
get = function(info) return Tql.blah2 end
},
},
},
profile = {
},
},
}
-- The default settings.
local defaults = {
profile = {
enable = true,
blah1 = false,
blah2 = false,
}
}
-- This runs when the AddOn is loaded by the client.
function Tql:OnInitialize()
-- Create the /tql slash command.
Tql:RegisterChatCommand("tql", "TqlSlash")
-- Loading the SavedVariables.
self.db = LibStub("AceDB-3.0"):New("TqlDB", defaults, "Default")
options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
-- Registering the options table.
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TqlOptions", options.args.general)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TqlLog", options.args.log)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TqlTracker", options.args.tracker)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TqlProfiles", options.args.profile)
-- Adding the AddOn to Blizzard's Interface Options frame.
self.TqlOptions = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TqlOptions", "Tag's Quest Log")
self.TqlLog = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TqlLog", "Quest Log", "Tag's Quest Log")
self.TqlTracker = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TqlTracker", "Quest Tracker", "Tag's Quest Log")
self.TqlProfiles = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TqlProfiles", "Profiles", "Tag's Quest Log")
end
-- This runs when the AddOn is enabled by the user.
function Tql:OnEnable()
end
-- This runs when the AddOn is disabled by the user.
function Tql:OnDisable()
end
-- Add a function to the /tql slash command.
function Tql:TqlSlash(input)
-- Open the Interface OPtions frame to Tag's Quest Log.
InterfaceOptionsFrame_OpenToCategory("Tag's Quest Log")
end
I have defined my SavedVariables as ## SavedVariables: TqlDB in my .toc file, if you were curious.
(Also on a small sidenote, how do I change the 'Profile' header inside my options? Adding a name = "Tag's Quest Log", does not work like with the other pages, probably because the Profiles page is pre-defined entirely. Chatter for example has changed it though, so it is possible. :p)
Your option handlers are getting/setting (for example) "Tql.blah2" instead of "Tql.db.profile.blah2". Doing the latter is how the visible options get linked in with the profile saved settings. The rest of your code would then examine Tql.db.profile.blah2 when it came time to make decisions during runtime (although since it would probably take place inside "member function", you'd likely write it as self.db.profile.blah2 instead).
The empty "profile = {}" in the options table can be removed entirely. It gets overwritten later when you assign options.args.profile as the generated Profiles tab. If you want to make changes to that tab, you'll need to do it after that point, e.g., options.args.profile.name = "The Profile Tab".
Thanks, but I fixed it already... it was a small typo.
Had a 'default' somewhere, where it should've been 'defaults'.
So far it's all working, thanks anyway though. :)
I've run into two small issues.
1) I can't seem to get my dropdown menus to work. I can't figure out how to define the values. I first worked from an AddOn that used some sort of sound lib, since I want to do the same, but when testing my AddOn without other AddOns it backfired so I'm trying to make a stand-alone dropdown menu first.
2) When testing my AddOn with other AddOns loaded, the Interface Options frame is wider than when I test my AddOn without other AddOns. How do I widthen (?) the Interface Options frame?
objectivesoundfile = {
name = "Objective completion sound",
desc = "Choose the sound to play when you complete a quest objective.",
type = "select",
style = "dropdown",
order = 2,
values = "",
disabled = function() return not Tql.db.profile.objectivesound end,
},
1) 'values' needs to be a table, or (if memory serves) a function that returns a table. The keys are what get passed to callbacks, and the values are what show up to the user.
2) What other addons are you loading?
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Do note that I have looked at the tutorials, but I can't find any good example code to help me with the issue I've run into.
I'm trying to create an options GUI for my AddOn, according to the tutorials this should work via AceConfigDialog-3.0. The piece of code from said tutorial does not seem to work though, probably because I'm using it wrong. ^^
What it should do: Add my AddOn into the Interface Options panel and create a Profiles subcategory. It's also supposed to open the Options GUI by using /tql and save the settings, though my primary problem is getting an Options GUI. :p
What happens in stead: I get the following Lua error:
Interface\AddOns\Tql\Tql.lua:42: attempt to index global 'self' (a nil value)
Tql.toc
Tql.lua
I think I'm also forgetting to register the main options besides adding the Profiles, but I'm kind of lost right now and can't figure it out at all. :(
Could anyone provide me with or tell me where to find a piece of example code I can work from, or show me where I went wrong with this piece of code? <:
is the same as:
and
is equivalent to:
so basically, "self" is only valid inside of a function defined via the table:function method unless it's explicitly defined.
you have two "self" references are outside of a function, so they're just normal variable references. since you don't define "self" as a local anywhere, it's looking for a global named self which doesn't exist.
judging by your code, you should probably substitute the "Tql" table in place of the "self" reference in your final two lines.
I was planning on slowly starting to make the config UI itself, but figured it would be best if I made some example options first and make sure my SavedVariables, default settings and Profiles work properly.
As you can guess, they dont. :p
No settings are saved through reloads, nor do the profiles seem to work.
- I think I might not have defined the local defaults properly.
- I think I'm not loading them properly, either.
- I think I haven't 'linked' my SavedVariables to my Profiles.. or something along those lines.
- I have a feeling I'm forgetting something else that I need to make my SavedVariables, profiles and Default profile work properly as well. :p
Here is once again, my Tql.xml code:
I have defined my SavedVariables as ## SavedVariables: TqlDB in my .toc file, if you were curious.
(Also on a small sidenote, how do I change the 'Profile' header inside my options? Adding a name = "Tag's Quest Log", does not work like with the other pages, probably because the Profiles page is pre-defined entirely. Chatter for example has changed it though, so it is possible. :p)
The empty "profile = {}" in the options table can be removed entirely. It gets overwritten later when you assign options.args.profile as the generated Profiles tab. If you want to make changes to that tab, you'll need to do it after that point, e.g., options.args.profile.name = "The Profile Tab".
I still can't manage to define the settings for the Default profile, though.
Had a 'default' somewhere, where it should've been 'defaults'.
So far it's all working, thanks anyway though. :)
I've run into two small issues.
1) I can't seem to get my dropdown menus to work. I can't figure out how to define the values. I first worked from an AddOn that used some sort of sound lib, since I want to do the same, but when testing my AddOn without other AddOns it backfired so I'm trying to make a stand-alone dropdown menu first.
2) When testing my AddOn with other AddOns loaded, the Interface Options frame is wider than when I test my AddOn without other AddOns. How do I widthen (?) the Interface Options frame?
Current Tql.lua: http://paste.wowace.com/2968/
Current dropdown menu code:
2) What other addons are you loading?