View Single Post
05-27-21, 08:36 PM   #1
Dixon Butz
A Deviate Faerie Dragon
 
Dixon Butz's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 13
Backdrop Fix Help

I have seen the code change posted for backdrops. I don't have a clue. Can anyone help me fix this very old abandoned addon? It's very small. KBTracker.
Probably and easy fix for those that know .lua I have tried.
Been using it forever. Worked in classic too.

This is the lua error on login:

Code:
Message: Interface\AddOns\KBTracker\KBTracker.lua:169: attempt to index global 'tframe' (a nil value)
Time: Thu May 27 22:32:14 2021
Count: 1
Stack: Interface\AddOns\KBTracker\KBTracker.lua:169: attempt to index global 'tframe' (a nil value)
[string "@Interface\AddOns\KBTracker\KBTracker.lua"]:169: in function `KBTracker_CreateMainFrame'
[string "@Interface\AddOns\KBTracker\KBTracker.lua"]:61: in function `KBTracker_OnLoad'
[string "@Interface\AddOns\KBTracker\KBTracker.lua"]:48: in function <Interface\AddOns\KBTracker\KBTracker.lua:48>

Locals: backdrop = <table> {
 backdropColor = <table> {
 }
 edgeSize = 14
 tileEdge = false
 backdropBorderColor = <table> {
 }
 tileSize = 16
 edgeFile = "Interface\DialogFrame\UI-DialogBox-Border"
 tile = false
 bgFile = "Interface\FrameGeneral\UI-Background-Rock"
 insets = <table> {
 }
}
(*temporary) = nil
(*temporary) = <table> {
 backdropColor = <table> {
 }
 edgeSize = 14
 tileEdge = false
 backdropBorderColor = <table> {
 }
 tileSize = 16
 edgeFile = "Interface\DialogFrame\UI-DialogBox-Border"
 tile = false
 bgFile = "Interface\FrameGeneral\UI-Background-Rock"
 insets = <table> {
 }
}
(*temporary) = 2.500000
(*temporary) = nil
(*temporary) = <table> {
 backdropColor = <table> {
 }
 edgeSize = 14
 tileEdge = false
 backdropBorderColor = <table> {
 }
 tileSize = 16
 edgeFile = "Interface\DialogFrame\UI-DialogBox-Border"
 tile = false
 bgFile = "Interface\FrameGeneral\UI-Background-Rock"
 insets = <table> {
 }
}
(*temporary) = <function> defined =[C]:-1
(*temporary) = <table> {
 backdropColor = <table> {
 }
 bgFile = "Interface\FrameGeneral\UI-Background-Rock"
 tile = false
 backdropBorderColor = <table> {
 }
 tileSize = 16
 edgeFile = "Interface\DialogFrame\UI-DialogBox-Border"
 tileEdge = false
 edgeSize = 14
 insets = <table> {
 }
}
(*temporary) = "insets"
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = <table> {
 top = 2.500000
 right = 2.500000
 left = 2.500000
 bottom = 2.500000
}
(*temporary) = "attempt to index global 'tframe' (a nil value)"
KBTBlueColor = ""
KBTTopColor = ""
KBTMiddleColor = ""
KBTBottomColor = ""
KBTWhiteColor = ""
This is the whole KBTracker.lua


Lua Code:
  1. --------------------------------------------------------------THESE COLORS SET THE TOP MIDDLE AND BOTTOM ROW COLORS
  2. local KBTWhiteColor = "|cFFFFFFFF";
  3. local KBTBlueColor = "|cFF0070fF";
  4. local KBTTopColor = "|cFFFFFF00";
  5. local KBTMiddleColor = "|cFFFF0000";
  6. local KBTBottomColor = "|cFF00FF00";
  7. local PlayerName = UnitName("Player");
  8.  
  9. local KBT_WasInBG = false;
  10. local KBT_IsInBG = false;
  11. local KBT_LastBG = "";
  12.  
  13. function KBT_TestFn()
  14.     KBT_Current_KillingBlows = 10;
  15.     KBT_Current_HonorKills = 10;
  16.    
  17.     KBT_Display_HK:SetText( KBTWhiteColor   .. "(KB)\n" ..
  18.                             KBTTopColor     .. KBT_Current_KillingBlows .. "\n" ..
  19.                             KBTMiddleColor  .. KBT_Last_KillingBlows .."\n" ..
  20.                             KBTBottomColor  .. KBT_Total_KillingBlows + KBT_Current_KillingBlows)
  21.    
  22.     KBT_Display_KB:SetText( KBTWhiteColor   .. "(HK)\n" ..
  23.                             KBTTopColor     .. KBT_Current_HonorKills .. "\n" ..
  24.                             KBTMiddleColor  .. KBT_Last_HonorKills .."\n" ..
  25.                             KBTBottomColor  .. KBT_Total_HonorKills + KBT_Current_HonorKills)
  26. end
  27.  
  28. local KBT_ListOfBattlegrounds = {
  29.     "Isle of Conquest",
  30.     "Alterac Valley",
  31.     "Arathi Basin",
  32.     "Eye of the Storm",
  33.     "Warsong Gulch",
  34.     "Strand of the Ancients",
  35.     "Twin Peaks",
  36.     "Battle for Gilneas"
  37. }
  38.  
  39. KBT_Current_KillingBlows = 0;
  40. KBT_Last_KillingBlows = 0;
  41. KBT_Total_KillingBlows = 0;
  42.  
  43. KBT_Current_HonorKills = 0;
  44. KBT_Last_HonorKills = 0;
  45. KBT_Total_HonorKills = 0;
  46.  
  47. KBTracker_OnLoadFunction = CreateFrame("FRAME");
  48. KBTracker_OnLoadFunction:SetScript("OnEvent", function()    KBTracker_OnLoad(); end)
  49. KBTracker_OnLoadFunction:RegisterEvent("VARIABLES_LOADED");
  50.  
  51. function KBTracker_OnLoad()
  52.  
  53.     if KBTrackerDBPC == nil then KBTrackerDBPC = {} end
  54.     if KBTrackerDBPC["x"] == nil then KBTrackerDBPC["x"] = 0 end
  55.     if KBTrackerDBPC["y"] == nil then KBTrackerDBPC["y"] = 0 end
  56.     if KBTrackerDBPC["point"] == nil then KBTrackerDBPC["point"] = "Center" end
  57.  
  58.    
  59.  
  60. -- create the frame to hold the data
  61.     KBTracker_CreateMainFrame()
  62.    
  63. -- create a frame that updates every 5 seconds to update the data
  64.     KBTracker_CreateUpdateFrame()
  65.    
  66.    
  67. -- setup slash commands
  68.     SLASH_KBT1 = "/kbt";
  69.     SLASH_KBT2 = "/hkt";
  70.     SLASH_KBT3 = "/kbtracker";
  71.     SlashCmdList["KBT"] =  KBTracker_Command;
  72. end
  73.  
  74. function KBTracker_CreateUpdateFrame()
  75.     KBT_UpdateTime = time()+10;
  76.     KBT_Update_Frame=CreateFrame("FRAME");
  77.     KBT_Update_Frame:SetScript("OnUpdate", function()
  78.         if time() >= KBT_UpdateTime then
  79.             KBT_UpdateTime = time()+10;
  80.             RequestBattlefieldScoreData()
  81.             KBTracker_ZoneChecker()
  82.             --print(time());
  83.         end;
  84.     end);
  85.    
  86.     KBTracker_UpdateDataFrame = CreateFrame("FRAME");
  87.     KBTracker_UpdateDataFrame:SetScript("OnEvent", function()   KBTracker_UpdateData(); end)
  88.     KBTracker_UpdateDataFrame:RegisterEvent("UPDATE_BATTLEFIELD_SCORE");
  89. end
  90.  
  91. function KBTracker_ZoneChecker()   
  92. local Zone = GetRealZoneText();
  93. local KBT_BGFound = false;
  94. local KBT_NewBG = false;
  95.  
  96.     --print(Zone)
  97.    
  98.     for i=1,#KBT_ListOfBattlegrounds do
  99.         if Zone == KBT_ListOfBattlegrounds[i] then
  100.             --print(KBT_ListOfBattlegrounds[i]);
  101.             KBT_BGFound = true;
  102.         end
  103.     end
  104.    
  105.     if KBT_WasInBG == true and KBT_BGFound == true and KBT_LastBG ~= Zone then
  106.         KBT_NewBG = true;
  107.     end
  108.    
  109.     if KBT_WasInBG == false and KBT_BGFound == true then
  110.         KBT_NewBG = true;
  111.     end
  112.    
  113.     if KBT_NewBG == true then
  114.         --print("|cff0070ffNew BG found")
  115.        
  116.         KBT_Total_KillingBlows = KBT_Total_KillingBlows + KBT_Current_KillingBlows;
  117.         KBT_Total_HonorKills   = KBT_Total_HonorKills   + KBT_Current_HonorKills;
  118.        
  119.         KBT_Last_KillingBlows = KBT_Current_KillingBlows;
  120.         KBT_Last_HonorKills   = KBT_Current_HonorKills;
  121.        
  122.         KBT_Current_KillingBlows = 0;
  123.         KBT_Current_HonorKills   = 0;
  124.        
  125.         KBT_LastBG = Zone;
  126.     end
  127.    
  128.     KBT_WasInBG = KBT_BGFound;
  129. end
  130.  
  131. function KBTracker_UpdateData()
  132. local Max = GetNumBattlefieldScores();
  133.  
  134.     if Max > 0 then
  135.         for i=1,Max do
  136.             local name, killingBlows, honorKills, _ = GetBattlefieldScore(i);
  137.             if name == PlayerName then
  138.                 --print(name)
  139.                 --print(killingBlows)
  140.                 --print(honorKills)
  141.                 --print(GetBattlefieldScore(i));
  142.                
  143.                
  144.                 if killingBlows > KBT_Current_KillingBlows then
  145.                     KBT_Current_KillingBlows = killingBlows;
  146.                 end
  147.                
  148.                 if honorKills > KBT_Current_HonorKills then
  149.                     KBT_Current_HonorKills   = honorKills;
  150.                 end
  151.                
  152.                 KBT_Display_HK:SetText( KBTWhiteColor   .. "(KB)\n" ..
  153.                                         KBTTopColor     .. KBT_Current_KillingBlows .. "\n" ..
  154.                                         KBTMiddleColor  .. KBT_Last_KillingBlows .."\n" ..
  155.                                         KBTBottomColor  .. KBT_Total_KillingBlows + KBT_Current_KillingBlows)
  156.                
  157.                 KBT_Display_KB:SetText( KBTWhiteColor   .. "(HK)\n" ..
  158.                                         KBTTopColor     .. KBT_Current_HonorKills .. "\n" ..
  159.                                         KBTMiddleColor  .. KBT_Last_HonorKills .."\n" ..
  160.                                         KBTBottomColor  .. KBT_Total_HonorKills + KBT_Current_HonorKills)
  161.             end
  162.         end
  163.     end
  164. end
  165.  
  166. function KBTracker_CreateMainFrame()
  167. local f = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate")
  168.  
  169.         tile = false,    -- true to repeat the background texture to fill the frame, false to scale it
  170.           -- size (width or height) of the square repeating background tiles (in pixels)
  171.           -- thickness of edge segments and square size of edge corners (in pixels)
  172.             -- distance from the edges of the frame to those of the background texture (in pixels)
  173.  
  174.  
  175.  
  176.  
  177. -- create the frame
  178.     KBT_Display_Frame:SetWidth(135);
  179.     KBT_Display_Frame:SetHeight(65);
  180.     KBT_Display_Frame:SetPoint(KBTrackerDBPC["point"],KBTrackerDBPC["x"],KBTrackerDBPC["y"]);
  181.     KBT_Display_Frame:SetBackdrop(backdrop);
  182.     --KBT_Display_Frame:Hide()
  183.    
  184. -- This allows the frame to be moved
  185.     KBT_Display_Frame:SetMovable(true)
  186.     KBT_Display_Frame:EnableMouse(true)
  187.     KBT_Display_Frame:SetScript("OnMouseDown",function()
  188.         KBT_Display_Frame:StartMoving()
  189.     end)
  190.     KBT_Display_Frame:SetScript("OnMouseUp",function()
  191.         KBT_Display_Frame:StopMovingOrSizing()
  192.  
  193.         local point, relativeTo, relativePoint, xOfs, yOfs = KBT_Display_Frame:GetPoint()
  194.         KBTrackerDBPC["point"] = point;
  195.         KBTrackerDBPC["x"] = xOfs;
  196.         KBTrackerDBPC["y"] = yOfs;
  197.     end)
  198.    
  199. -- create the font strings
  200.     KBT_Display_Types =  KBT_Display_Frame:CreateFontString("KBT_Display_Types" ,"ARTWORK","GameFontNormal");
  201.     KBT_Display_Types:SetPoint("TopLeft", KBT_Display_Frame, "TopLeft", 5, -8)
  202.     KBT_Display_Types:SetText(  KBTBlueColor    .. "KBT     \n" ..
  203.                                 KBTTopColor     .. "This BG:\n" ..
  204.                                 KBTMiddleColor  .. "Last BG:\n" ..
  205.                                 KBTBottomColor  .. "Session:")
  206.     KBT_Display_Types:SetJustifyH("Right")
  207.    
  208.     KBT_Display_HK =  KBT_Display_Frame:CreateFontString("KBT_Display_HK" ,"ARTWORK","GameFontNormal");
  209.     KBT_Display_HK:SetPoint("TopLeft", KBT_Display_Frame, "TopLeft", 55, -8)
  210.     KBT_Display_HK:SetText( KBTWhiteColor   .. "(KB)\n" ..
  211.                             KBTTopColor     .. KBT_Current_KillingBlows .. "\n" ..
  212.                             KBTMiddleColor  .. KBT_Last_KillingBlows .."\n" ..
  213.                             KBTBottomColor  .. KBT_Total_KillingBlows)
  214.     KBT_Display_HK:SetJustifyH("Center")
  215.    
  216.     KBT_Display_KB =  KBT_Display_Frame:CreateFontString("KBT_Display_KB" ,"ARTWORK","GameFontNormal");
  217.     KBT_Display_KB:SetPoint("TopLeft", KBT_Display_Frame, "TopLeft", 90, -8)
  218.     KBT_Display_KB:SetText( KBTWhiteColor   .. "(HK)\n" ..
  219.                             KBTTopColor     .. KBT_Current_HonorKills .. "\n" ..
  220.                             KBTMiddleColor  .. KBT_Last_HonorKills .."\n" ..
  221.                             KBTBottomColor  .. KBT_Total_HonorKills)
  222.     KBT_Display_KB:SetJustifyH("Center")
  223. end
  224.  
  225. function KBTracker_Command(cmd)
  226.     if cmd == "center" then
  227.         KBT_Display_Frame:ClearAllPoints();
  228.         KBT_Display_Frame:SetPoint("Center");
  229.     elseif cmd == "show" then
  230.         if KBT_Display_Frame:IsShown() then
  231.             KBT_Display_Frame:Hide();
  232.         else
  233.             KBT_Display_Frame:Show();
  234.         end
  235.     else
  236.         print(KBTBlueColor .. "Killing Blow Tracker")
  237.         print("Commands:")
  238.         print("show - Toggle the tracker frame")
  239.         print("center - Reset the position of the window")
  240.     end
  241. end
  242.  
  243. local KBT_DataObj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("KB Tracker", {
  244.     text = "KBT",
  245.     type = "data source",
  246.     icon = "Interface\\Icons\\spell_deathknight_subversion",
  247.     OnClick = function(clickedframe, button)
  248.         if button == "LeftButton" then
  249.             if KBT_Display_Frame:IsShown() then
  250.                 KBT_Display_Frame:Hide();
  251.             else
  252.                 KBT_Display_Frame:Show();
  253.             end
  254.         elseif button == "RightButton" then
  255.             KBT_Display_Frame:ClearAllPoints();
  256.             KBT_Display_Frame:SetPoint("Center");
  257.         end
  258.     end,
  259. })
  260.  
  261. if KBT_DataObj ~= nil then
  262.  
  263.     function KBT_DataObj:OnTooltipShow()
  264.         self:AddLine(KBTBlueColor .. "Killing Blow Tracker\n\n" .. KBTWhiteColor .. "Left Click: Toggle Window\nRight Click: Recenter Window")
  265.     end
  266.  
  267.     function KBT_DataObj:OnEnter()
  268.         GameTooltip:SetOwner(self, "ANCHOR_NONE")
  269.         GameTooltip:SetPoint("TOPLEFT", self, "BOTTOMLEFT")
  270.         GameTooltip:ClearLines()
  271.         KBT_DataObj.OnTooltipShow(GameTooltip)
  272.         GameTooltip:Show()
  273.     end
  274.  
  275.     function KBT_DataObj:OnLeave()
  276.         GameTooltip:Hide()
  277.     end
  278. end
  Reply With Quote