Thread Tools Display Modes
03-15-12, 09:34 PM   #1
Crober
A Murloc Raider
 
Crober's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 9
Problem adding options

I am attempting to add options to my addon Holy Power Indicator.

I followed the tutorial found at http://forums.wowace.com/showthread.php?t=12050

The options show up fine but when I attempt to gain a charge of holy power i get the error "..\AddOns\HPIDev\Core.lua line 151: attempt to index field 'db' (a nil value)"

I can't seem to figure out what the problem is. Here is the code pastebin.

Any ideas/help is appreciated.

Also asked on CurseForge http://forums.curseforge.com/showthr...858#post320858
  Reply With Quote
03-16-12, 02:32 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
See my reply on your CurseForge thread.
  Reply With Quote
03-16-12, 02:41 AM   #3
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Basically, you have 2 problems with how you're referring to your saved variables. See here:
lua Code:
  1. function events:UNIT_POWER(source,type)
  2.     if source == "player" and type == "HOLY_POWER" then
  3.         local power = UnitPower("player",9)
  4.  
  5.         if power == 1 then
  6.             texture:SetTexture(self.db.textureSelect.."1.tga")
  7.             frame:Show()
  8.  
  9.         elseif power == 2 then
  10.             texture:SetTexture(self.db.textureSelect.."2.tga")
  11.             frame:Show()
  12.  
  13.         elseif power == 3 then
  14.             texture:SetTexture(self.db.textureSelect.."3.tga")
  15.             frame:Show()
  16.  
  17.         elseif power == 0 then
  18.             frame:Hide()
  19.         end
  20.     end
  21. end
"self" in this function refers to "events", so it's trying to access events.db instead of HolyPowerIndicator.db.

The other problem is that HolyPowerIndicator.db is defined here:
lua Code:
  1. self.db = LibStub("AceDB-3.0"):New("HolyPowerIndicatorDB", defaults, "Default")
to refer to the table "defaults", but the data you're actually interested in is in defaults.profile.

So basically you need to replace all instances of "self.db" (ouside of your OnInitialize function) with "HolyPowerIndicator.db.profile".
  Reply With Quote
03-16-12, 02:58 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I already explained that in great detail in the other thread, which is why I posted here that I already replied there, so that others would not waste their time typing the same thing over again.
  Reply With Quote
03-16-12, 03:04 AM   #5
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Sorry, I was typing before you posted
  Reply With Quote
03-16-12, 10:04 PM   #6
Crober
A Murloc Raider
 
Crober's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 9
From CurseForge:
Thank you, that helped a lot. I think as I looked through the code and your comments I was able to pretty much understand what was going on.

I did run into an issue when trying to change the alpha (it would just snap back to the default value), I noticed the set function had

Code:
set = function(_, value) HolyPowerIndicator.db.profile.Alpha = value end,
I changed it to db.profile.alpha and that seemed to fix it.

Sometimes on /reload ui it unlocks the frame and shows the 3 charge texture, I removed "not" from

Code:
function HolyPowerIndicator:ToggleFrameLock(value)
	if value ~= nil then
		value = not self.db.profile.locked
	end
which fixes that, but I don't know if that would cause another issue.

Also is it possible to have the frame update as the user changes the options without a ui reload?
  Reply With Quote
03-17-12, 02:12 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also replied again on CurseForge.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem adding options


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