Quantcast I need better eyes to spot the bug please - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
01-20-20, 10:54 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,107
I need better eyes to spot the bug please

I am rewriting FeedTillers to address some long-standing issues and add some functionality. Of course now I ran into bugs, and I can't spot the cause.

The Broker menu isn't displaying when you mouse over the plugin; and when you click the plugin to sort either by Tiller name or Tiller item, I am getting nil errors. Great, so it can't find the item or name. But I can't spot why.

Error #1
Lua Code:
  1. 1x FeedTillers\FeedTillers-@project-version@.lua:93: attempt to compare two nil values
  2. [string "@FeedTillers\F[email protected]@.lua"]:93: in function <FeedTillers\FeedTillers.lua:92>
  3. [string "=[C]"]: in function `sort'
  4. [string "@FeedTillers\F[email protected]@.lua"]:114: in function `OnClick'
  5. [string "@ChocolateBar\Chocolate.lua"]:289: in function <ChocolateBar\Chocolate.lua:286>
  6.  
  7. Locals:
  8. a = <table> {
  9.  y = 33.800000
  10.  x = 48.200000
  11.  itemID = 74654
  12.  questID = 30421
  13.  factionID = 1283
  14. }
  15. b = <table> {
  16.  questID = 30439
  17.  factionID = 1273
  18.  y = 49.200000
  19.  x = 52.600000
  20.  name = "Jogu the Drunk"
  21.  noop = "Jogu's easy to find - gazing into the bottom of a bottle of the cheapest Stormstout Brewery has to offer."
  22.  itemID = 74643
  23.  standingID = 1
  24. }
  25. (*temporary) = nil
  26. (*temporary) = nil
  27. (*temporary) = "attempt to compare two nil values"

Error #2
Lua Code:
  1. 1x FeedTillers\FeedTillers-@project-version@.lua:90: attempt to compare nil with string
  2. [string "@FeedTillers\F[email protected]@.lua"]:90: in function <FeedTillers\FeedTillers.lua:89>
  3. [string "=[C]"]: in function `sort'
  4. [string "@FeedTillers\F[email protected]@.lua"]:114: in function `OnClick'
  5. [string "@ChocolateBar\Chocolate.lua"]:289: in function <ChocolateBar\Chocolate.lua:286>
  6.  
  7. Locals:
  8. a = <table> {
  9.  y = 33.800000
  10.  x = 48.200000
  11.  itemID = 74654
  12.  questID = 30421
  13.  factionID = 1283
  14. }
  15. b = <table> {
  16.  questID = 30439
  17.  factionID = 1273
  18.  y = 49.200000
  19.  x = 52.600000
  20.  name = "Jogu the Drunk"
  21.  noop = "Jogu's easy to find - gazing into the bottom of a bottle of the cheapest Stormstout Brewery has to offer."
  22.  item = "Sauteed Carrots"
  23.  itemID = 74643
  24.  standingID = 1
  25. }
  26. (*temporary) = nil
  27. (*temporary) = "Jogu the Drunk"
  28. (*temporary) = "attempt to compare nil with string"

And the full code
Lua Code:
  1. --[[
  2.     -- file and project errata --
  3.     Project Author:     @[email protected]
  4.     Project Date:       @[email protected]
  5.     Project Version:    @[email protected]
  6.     Project Revision:   @[email protected]
  7.  
  8.     File Author:        @[email protected]
  9.     File Date:          @[email protected]
  10.     File Revision:      @[email protected]
  11. ]]--
  12.  
  13. local ADDON, _ = ...
  14. local ADDON_TITLE = GetAddOnMetadata(ADDON, "Title")
  15. local TILLERS = GetFactionInfoByID(1272)
  16. local LOCALE = GetLocale()
  17. local event_frame = CreateFrame("frame")
  18. local TomTom = TomTom
  19.  
  20. local L = setmetatable({}, {__index = function(t, k)
  21.     local v = tostring(k)
  22.     rawset(t, k, v)
  23.     return v
  24. end})
  25.  
  26. -- translate the tooltips
  27. --[[
  28. -- don't actually need enUS as that's the default. using this as a reminder
  29. if LOCALE == "enUS" then
  30. L["Click a Tiller's line to set a waypoint in TomTom"] = true
  31. L["Click the plugin to sort by Tiller name or item name"] = true
  32. L["Hold the <Control> key and click to hide Best Friend Tillers"] = true
  33. L["Hold the <Shift> key and click to hide already fed Tillers"] = true
  34. return end
  35. ]]--
  36.  
  37. if LOCALE == "deDE" then
  38. [email protected](locale="deDE", format="lua_additive_table")@
  39. return end
  40.  
  41. if LOCALE == "esES" or LOCALE == "esMX" then
  42. [email protected](locale="esES", format="lua_additive_table")@
  43. return end
  44.  
  45. if LOCALE == "frFR" then
  46. [email protected](locale="frFR", format="lua_additive_table")@
  47. return end
  48.  
  49. if LOCALE == "itIT" then
  50. [email protected](locale="itIT", format="lua_additive_table")@
  51. return end
  52.  
  53. if LOCALE == "koKR" then
  54. [email protected](locale="koKR", format="lua_additive_table")@
  55. return end
  56.  
  57. if LOCALE == "ptBR" then
  58. [email protected](locale="ptBR", format="lua_additive_table")@
  59. return end
  60.  
  61. if LOCALE == "ruRU" then
  62. [email protected](locale="ruRU", format="lua_additive_table")@
  63. return end
  64.  
  65. if LOCALE == "zhCN" then
  66. [email protected](locale="zhCN", format="lua_additive_table")@
  67. return end
  68.  
  69. if LOCALE == "zhTW" then
  70. [email protected](locale="zhTW", format="lua_additive_table")@
  71. return end
  72.  
  73. local qtip = LibStub("LibQTip-1.0")
  74.  
  75. local npcs = {
  76.     { factionID = 1273, itemID = 74643, questID = 30439, x = 52.6, y = 49.2 }, -- Jogu the Drunk
  77.     { factionID = 1275, itemID = 74651, questID = 30386, x = 31.6, y = 58.0 }, -- Ella
  78.     { factionID = 1276, itemID = 74649, questID = 30396, x = 31.0, y = 53.0 }, -- Old Hillpaw
  79.     { factionID = 1277, itemID = 74647, questID = 30402, x = 34.4, y = 46.8 }, -- Chee Chee
  80.     { factionID = 1278, itemID = 74645, questID = 30408, x = 29.6, y = 30.6 }, -- Sho
  81.     { factionID = 1279, itemID = 74642, questID = 30414, x = 44.6, y = 34.0 }, -- Haohan Mudclaw
  82.     { factionID = 1280, itemID = 74652, questID = 30433, x = 45.0, y = 33.8 }, -- Tina Mudclaw
  83.     { factionID = 1281, itemID = 74644, questID = 30390, x = 53.2, y = 51.6 }, -- Gina Mudclaw
  84.     { factionID = 1282, itemID = 74655, questID = 30427, x = 41.6, y = 30.0 }, -- Fish Fellreed
  85.     { factionID = 1283, itemID = 74654, questID = 30421, x = 48.2, y = 33.8 }, -- Farmer Fung
  86. }
  87.  
  88. local tooltip = "NAME"
  89. local sortByName = function(a, b)
  90.     return a.name < b.name
  91. end
  92. local sortByItem = function(a, b)
  93.     return a.item < b.item
  94. end
  95.  
  96. local function UseTomTom(npc)
  97.     local x, y = npc.x, npc.y
  98.     local opts = {title = GetFactionInfoByID(npc.factionID), persistant = true, minimap = true, world = true, crazy = true}
  99.     TomTom:AddWaypoint(376, x, y, opts) -- 376 is the uiMapID for Valley of the Four Winds
  100. end
  101.  
  102. local function CreateBroker()
  103.     LibStub("LibDataBroker-1.1"):NewDataObject(ADDON, {
  104.         type = "data source",
  105.         text = ADDON_TITLE,
  106.         icon = [[Interface/ICONS/Achievement_Profession_ChefHat]],
  107.         OnClick = function(self)
  108.             if IsShiftKeyDown() then
  109.                 FeedTillersDB.hideComplete = not FeedTillersDB.hideComplete
  110.             elseif IsControlKeyDown() then
  111.                 FeedTillersDB.hideBestFriends = not FeedTillersDB.hideBestFriends
  112.             else
  113.                 FeedTillersDB.currentSort = FeedTillersDB.currentSort == "NAME" and "ITEM" or "NAME"
  114.                 sort(npcs, FeedTillersDB.currentSort == "NAME" and sortByName or sortByItem)
  115.             end
  116.  
  117.             self:GetScript("OnLeave")(self)
  118.             self:GetScript("OnEnter")(self)
  119.         end,
  120.         OnEnter = function(self)
  121.             TILLERS = TILLERS or GetFactionInfoByID(1272)
  122.             tooltip = qtip:Acquire("FeedTillersTT", 3, "LEFT", "LEFT", "RIGHT")
  123.             tooltip:AddHeader(TILLERS, ITEMS, COMPLETE)
  124.             local line
  125.             local hideComplete = FeedTillersDB.hideComplete
  126.             local hideBestFriends = FeedTillersDB.hideBestFriends
  127.  
  128.             for i = 1, #npcs do
  129.                 local npc = npcs[i]
  130.                 npc.name, npc.noop, npc.standingID = GetFactionInfoByID(npc.factionID) -- npc.noop is not used by FeedTillers
  131.                 npc.item = npc.item or GetItemInfo(npc.itemID)
  132.                 hideBestFriends = hideBestFriends == true and npc.standingID == 8
  133.  
  134.                 if not npc.item then
  135.                     print("cFFFF0000" .. L["FeedTillers error:"] .. "|r " .. L["the food item is being cached. Please wait and try viewing the display a few times until it is updated."])
  136.                 end
  137.  
  138.                 if not hideBestFriends then
  139.                     if not IsQuestFlaggedCompleted(npc.questID) then
  140.                         -- note "line" is no longer local to this scope!
  141.                         local count = GetItemCount(npc.itemID)
  142.                         line = tooltip:AddLine(npc.name, npc.item, format("%d/%d", count, 5))
  143.                         if TomTom then
  144.                             tooltip:SetScript(line, "OnMouseUp", UseTomTom, npc)
  145.                             tooltip:SetHighlightTexture(1, 1, 1, 0.7)
  146.                         end
  147.  
  148.                         if count < 5 then
  149.                             tooltip:SetLineColor(line, 1, 0.1, 0.1, 0.3)
  150.                         end
  151.                     elseif not hideComplete then
  152.                         line = tooltip:AddLine(npc.name, npc.item, YES)
  153.                         tooltip:SetLineColor(line, 0.1, 1, 0.1, 0.3)
  154.                     end
  155.                 end
  156.             end
  157.             sort(npcs, sortByName)
  158.  
  159.             if not line then
  160.                 hideComplete = nil
  161.                 hideBestFriends = nil
  162.                 self:GetScript("OnLeave")(self)
  163.                 return self:GetScript("OnEnter")(self)
  164.             end
  165.  
  166.             line = tooltip:AddLine(" ") -- blank line
  167.  
  168.             line = tooltip:AddLine(" ")
  169.             tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Click the plugin to sort by Tiller name or item name"], "LEFT", 3)
  170.  
  171.             line = tooltip:AddLine(" ")
  172.             tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Shift> key and click to hide already fed Tillers"], "LEFT", 3)
  173.  
  174.             line = tooltip:AddLine(" ")
  175.             tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Hold the <Control> key and click to hide Best Friend Tillers"], "LEFT", 3)
  176.  
  177.             if TomTom then
  178.                 line = tooltip:AddLine(" ")
  179.                 tooltip:SetCell(line, 1, NORMAL_FONT_COLOR_CODE .. L["Click a Tiller's line to set a waypoint in TomTom"], "LEFT", 3)
  180.             end
  181.  
  182.             tooltip:SmartAnchorTo(self)
  183.             tooltip:Show()
  184.         end,
  185.         OnLeave = function(self)
  186.             if qtip:IsAcquired("FeedTillersTT") then
  187.                 qtip:Release(tooltip)
  188.             end
  189.             tooltip = nil
  190.         end
  191.     })
  192. end
  193.  
  194. event_frame:RegisterEvent("PLAYER_LOGIN")
  195. event_frame:SetScript("OnEvent", function(self, ...)
  196.     if ... == "PLAYER_LOGIN" then
  197.         FeedTillersDB = FeedTillersDB or {}
  198.         FeedTillersDB.hideComplete = FeedTillersDB.hideComplete or false
  199.         FeedTillersDB.currentSort = FeedTillersDB.currentSort or "NAME"
  200.         FeedTillersDB.hideBestFriends = FeedTillersDB.hideBestFriends or false
  201.  
  202.         -- clean up old saved variables
  203.         FeedTillers_hideComplete = nil
  204.         FeedTillers_currentSort = nil
  205.  
  206.         CreateBroker()
  207.     end
  208. end)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » I need better eyes to spot the bug please

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