Quantcast
"Problem" with LibDataBroker - WoWInterface
Thread Tools Display Modes
04-27-16, 03:06 PM   #1
flow0284
An Aku'mai Servant
Join Date: Jan 2015
Posts: 39
Question "Problem" with LibDataBroker

Hi,

i have a little problem using libdatabroker for a minimap button and interacting with mousebuttons.

first of all here is my code
Lua Code:
  1. addon = LibStub("AceAddon-3.0"):NewAddon("MillButton", "AceConsole-3.0")
  2. local L = LibStub("AceLocale-3.0"):GetLocale("MillButton")
  3. local MillButtonLDB = LibStub("LibDataBroker-1.1"):NewDataObject("MillButtonIcon", {
  4.     type = "data source",
  5.     text = "MillButton",
  6.     icon = "Interface\\Icons\\Ability_Miling",
  7.     OnClick = function(_, button)
  8.         if button == "LeftButton" then
  9.             if InterfaceOptionsFrame:IsVisible() then
  10.                 InterfaceOptionsFrame:Hide()
  11.                 -- Hide the UI panel behind blizz options.
  12.                 HideUIPanel(GameMenuFrame)
  13.             else
  14.             InterfaceOptionsFrame_OpenToCategory("MillButton")
  15.             Options:SetScript("OnShow", nil)
  16.             end
  17.         end
  18.         if button == "RightButton" then
  19.             MillButtonSetup()
  20.         end
  21.     end,
  22.     OnTooltipShow = function(tooltip)
  23.         tooltip:SetText("MillButton")
  24.         tooltip:AddLine(GetAddOnMetadata(ADDON, "Version"),1,1,1)
  25.         tooltip:AddLine(" ")
  26.         tooltip:AddLine(L["r_mouse1"]..": |cFFFFFFFF"..L["r_mouse2"].."|r")
  27.         tooltip:AddLine(L["l_mouse1"]..": |cFFFFFFFF"..L["l_mouse2"].."|r")
  28.         tooltip:Show()
  29.     end
  30. })
  31.  
  32. local icon = LibStub("LibDBIcon-1.0")
  33.  
  34. function addon:OnInitialize()
  35.     self.db = LibStub("AceDB-3.0"):New("MillButtonMinimap", {
  36.         profile = {
  37.             minimap = {
  38.                 hide = false,
  39.             },
  40.         },
  41.     })
  42.     icon:Register("MillButtonIcon", MillButtonLDB, self.db.profile.minimap)
  43.     self:RegisterChatCommand("mbtnmmap", "ComMbtnMiniMapIcn")
  44. end
  45.  
  46. function addon:ComMbtnMiniMapIcn()
  47.     self.db.profile.minimap.hide = not self.db.profile.minimap.hide
  48.     if self.db.profile.minimap.hide then
  49.         icon:Hide("MillButtonIcon")
  50.     else
  51.         icon:Show("MillButtonIcon")
  52.     end
  53. end

in line 19 i will run a function after a rightclick

here the function:
Lua Code:
  1. function MillButtonSetup()
  2.     if ( IsPlayerSpell(51005) ) then
  3.         local bag, slot = findherb()
  4.         if (not bag or not slot) or LootFrame:IsVisible() or CastingBarFrame:IsVisible() or UnitCastingInfo("player") then
  5.         -- do nothing if no herb, if looting or casting
  6.             MillButton:SetAttribute("macrotext","")
  7.             if not bag then
  8.                 DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00MillButton: |r"..L["error"])
  9.             end
  10.         else
  11.             MillButton:SetAttribute("macrotext","/"..L["macro_cast"].." "..mill_spell.."\n/"..L["macro_use"].." "..bag.." "..slot)
  12.         end
  13.     end
  14.     if not ( IsPlayerSpell(51005) ) then
  15.         local bag, slot = findherb()
  16.         if (not bag or not slot) or LootFrame:IsVisible() or CastingBarFrame:IsVisible() or UnitCastingInfo("player") then
  17.         -- do nothing if no herb, if looting or casting
  18.             MillButton:SetAttribute("macrotext","")
  19.             if not bag then
  20.                 DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00MillButton: |r"..L["error"])
  21.             end
  22.         else
  23.             MillButton:SetAttribute("macrotext","/"..L["macro_use"].." item:114942".." ".."\n/"..L["macro_use"].." "..bag.." "..slot)
  24.         end
  25.     end
  26. end

so if the player is no scribe (has no spell in his spellbook with the spellid 51005) then i will use the item 114942 (draenic mortar). this doesn't work. the line 23 will not run. there is no lua error. if i run this function via macro ingame it will work but not through the minimapbutton.

later i will add a lookup for the draenic mortar in the players bag to prevent errors if the item is not present in the players bag.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » "Problem" with LibDataBroker

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