Thread Tools Display Modes
11-16-19, 07:24 AM   #1
StafordDev
A Murloc Raider
Join Date: May 2016
Posts: 7
Creating AddOn minimap button using LibDBIcon

As a developer of PoisonCharges addon (https://www.curseforge.com/wow/addons/poisoncharges) I wanted to update it to the latest WoW Classic version 1.13.2. But I ran into a number of problems trying to remake a minimap button. I tried to use LibDBIcon but can't make it to work because I never worked with libraries when developing addons for WoW.
What I did:
1) copied following libraries to Interface/Addons/PoisonCharges/Libs folder: AceDB-3.0, CallbackHandler-1.0, LibDataBroker-1.1, LibDBIcon-1.0, LibSharedMedia-3.0, LibStub;
2) tried to load them with following XML code (embeds.xml):
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">

<!--@no-lib-strip@-->
<Script file="Libs\LibStub\LibStub.lua"/>
<Include file="Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
<Include file="Libs\AceDB-3.0\AceDB-3.0.xml"/>
<!--@end-no-lib-strip@-->
<Script file="Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua"/>
<!--@no-lib-strip@-->
<Script file="Libs\LibSharedMedia-3.0\LibSharedMedia-3.0.lua"/>
<Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/>
<!--@end-no-lib-strip@-->

</Ui>
3) of course added it to .toc file:
Code:
...

PoisonCharges.lua
PoisonCharges.xml

embeds.xml
4) put following code into OnEvent function (which fires only once when the addon is loaded):
Code:
    local LDB = LibStub("LibDataBroker-1.1", true)
    local LDBIcon = LDB and LibStub("LibDBIcon-1.0", true)
    if LDB then
        local PC_MinimapBtn = LDB:NewDataObject("PoisonCharges", {
            type = "launcher",
			text = "PoisonCharges",
            icon = "Interface\\AddOns\\PoisonCharges\\media\\PoisonCharges_Icon",
            OnClick = function(_, button)
                if button == "LeftButton" then PC_SettingsToggle() end
            end,
            OnTooltipShow = function(tt)
                tt:AddLine("PoisonCharges")
                tt:AddLine("|cffffff00Click|r to open the PoisonCharges settings window.")
            end,
        })
        if LDBIcon then
            LDBIcon:Register("PoisonCharges", PC_MinimapBtn, PC_MinimapPos) -- PC_MinimapPos is a SavedVariable which is set to 90 as default
        end
    end
5) and this is the error I get:
Code:
Message: ...s\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:314: attempt to index local 'db' (a number value)
Time: Sat Nov 16 16:14:49 2019
Count: 1
Stack: ...s\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:314: attempt to index local 'db' (a number value)
...s\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:314: in function `Register'
Interface\AddOns\PoisonCharges\PoisonCharges.lua:52: in function `PoisonCharges_OnEvent'
[string "*:OnEvent"]:1: in function <[string "*:OnEvent"]:1>

Locals: self = <table> {
 Register = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:311
 callbacks = <table> {
 }
 Unlock = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:333
 Lock = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:321
 ShowOnEnter = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:409
 SetButtonToPosition = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:442
 SetButtonRadius = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:433
 UnregisterAllCallbacks = <function> defined @Interface\AddOns\PoisonCharges\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:174
 notCreated = <table> {
 }
 radius = 5
 GetMinimapButton = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:384
 IsRegistered = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:359
 tooltip = LibDBIconTooltip {
 }
 RegisterCallback = <function> defined @Interface\AddOns\PoisonCharges\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:90
 Show = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:350
 GetButtonList = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:425
 UnregisterCallback = <function> defined @Interface\AddOns\PoisonCharges\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:153
 Refresh = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:363
 objects = <table> {
 }
 callbackRegistered = true
 Hide = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:345
 IconCallback = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:25
}
name = "PoisonCharges"
object = <table> {
}
db = 359.542840
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index local 'db' (a number value)"
lib = <table> {
 Register = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:311
 callbacks = <table> {
 }
 Unlock = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:333
 Lock = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:321
 ShowOnEnter = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:409
 SetButtonToPosition = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:442
 SetButtonRadius = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:433
 UnregisterAllCallbacks = <function> defined @Interface\AddOns\PoisonCharges\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:174
 notCreated = <table> {
 }
 radius = 5
 GetMinimapButton = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:384
 IsRegistered = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:359
 tooltip = LibDBIconTooltip {
 }
 RegisterCallback = <function> defined @Interface\AddOns\PoisonCharges\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:90
 Show = <function> defined @Interface\AddOns\PoisonCharges\Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua:350
 GetButtonList = <fun
Thus I'm asking for help: how to make a working movable minimap button for your addon?

Last edited by StafordDev : 11-16-19 at 07:26 AM.
  Reply With Quote
11-16-19, 08:59 AM   #2
StafordDev
A Murloc Raider
Join Date: May 2016
Posts: 7
For anyone wondering: if I replace
Code:
LDBIcon:Register("PoisonCharges", PC_MinimapBtn, PC_MinimapPos)
with
Code:
LDBIcon:Register("PoisonCharges", PC_MinimapBtn, self.PC_MinimapPos)
it starts working. Now the second problem: I can move the button, but how I can save the new position?
  Reply With Quote
11-16-19, 10:59 AM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
The third value is your storage table. Simply use a table of your savedvariables.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-16-19, 11:58 AM   #4
StafordDev
A Murloc Raider
Join Date: May 2016
Posts: 7
As I mentioned in the first post, third parameter - PC_MinimapPos - is already a SavedVariable.
  Reply With Quote
11-16-19, 12:20 PM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
And the default value of this is a table?

Edit: The important part of your error is this


Code:
name = "PoisonCharges"
object = <table> {
}
db = 359.542840
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index local 'db' (a number value)"
The first two values look ok. The third should be a table but looks like you passed the value of table['minimapPos'] from a previous try or sth.
__________________
The cataclysm broke the world ... and the pandas could not fix it!

Last edited by Rilgamon : 11-16-19 at 01:11 PM.
  Reply With Quote
11-16-19, 01:48 PM   #6
StafordDev
A Murloc Raider
Join Date: May 2016
Posts: 7
The error described in the first post has already been fixed. And yes, PC_MinimapPos is already a table even in defaults. Initialization of variables:
Code:
	-- initialize variables if this is the first time this addon loaded
	if PC_State == nil then
		PC_State = 1
	end
	if PC_MH == nil then
		PC_MH = "Not selected"
	end
	if PC_OH == nil then
		PC_OH = "Not selected"
	end
	if PC_MinimapPos == nil then
		PC_MinimapPos = { 90 }
	end
And here are the contents of PoisonCharges.lua in SavedVariables with default values as a proof:
Code:
PC_State = 1
PC_MH = "Not selected"
PC_OH = "Not selected"
PC_MinimapPos = {
	90, -- [1]
}
There're no errors during gameplay, the addon works perfectly but if I move minimap button the new position is not saved.
  Reply With Quote
11-16-19, 01:55 PM   #7
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
The table should look like this.
Code:
{
	["minimapPos"] = 206.3376812873,
	["hide"] = false,
}
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-16-19, 02:03 PM   #8
StafordDev
A Murloc Raider
Join Date: May 2016
Posts: 7
Now I did as you said and also replaced
Code:
LDBIcon:Register("PoisonCharges", PC_MinimapBtn, self.PC_MinimapPos)
with
Code:
LDBIcon:Register("PoisonCharges", PC_MinimapBtn, PC_MinimapPos)
And now it works perfectly. Thanks for your help!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Creating AddOn minimap button using LibDBIcon

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