Thread Tools Display Modes
10-07-15, 01:45 AM   #1
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Lua error on GuildControlGetRankName?

Working on a new addon, a guild browser, and its progressing quite nicely.
But once in a while, I get an annoying lua error.
According to BugSack (see below) i get the following error.

Lua Code:
  1. 6x Gildam\GildamGuild.lua:468: attempt to index field '?' (a nil value)
  2. Gildam\GildamGuild.lua:468: in function `Gildam_GG_Update'
  3. Gildam\GildamUI.lua:376: in function `Gildam_Toggle_UI'
  4. Gildam\GildamMain.lua:563: in function <Gildam\GildamMain.lua:557>
  5. Titan\LDBToTitan.lua:273: in function <Titan\LDBToTitan.lua:271>
  6.  
  7. Locals:

This originates from the following piece of code.
Thought the If statement (if GuildControlGetRankName(i) ~= nil then) would catch the error, but no luck.
Anyone out there have a clue?


Lua Code:
  1. --  Set the names of the ranks 
  2.     for i = 1, GuildControlGetNumRanks() do
  3.         if GuildControlGetRankName(i) ~= nil then
  4.             Gildam_GGRC1.list[i].name1:SetText(GuildControlGetRankName(i))
  5.             Gildam_GGRC1.list[i].name2:SetText(GetNumMembersInRank(i))
  6.             GuildControlSetRank(i)
  7.             local guildchat_listen, guildchat_speak, officerchat_listen, officerchat_speak, promote, demote,
  8.                 invite_member, remove_member, set_motd, edit_public_note, view_officer_note, edit_officer_note,
  9.                 modify_guild_info, _, withdraw_repair, withdraw_gold, create_guild_event = GuildControlGetRankFlags();
__________________
Better to fail then never have tried at all.
  Reply With Quote
10-07-15, 02:36 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
We don't have line numbers, but the error is saying the table key you're trying to access doesn't exist.

In other words, any of these 4 table lookups may not exist when that code is run: Gildam_GGRC1.list, Gildam_GGRC1.list[i], Gildam_GGRC1.list[i].name1, Gildam_GGRC1.list[i].name2

The most likely missing table entry is Gildam_GGRC1.list[i], and without the rest of the script we can't see where that's being created.
  Reply With Quote
10-07-15, 03:51 AM   #3
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
@semlar
You are right of course.
So there is the whole lua file.
The "creation" part is is done from line 310 till 396.

And is there a better way to post almost 600 lines of code?

Lua Code:
  1. --[[    *** Gildam ***
  2. Written by : Yukyuk, EU-Moonglade
  3. --]]
  4.  
  5. local FOLDER_NAME, private = ...
  6. local addon = LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
  7.  
  8. --  Set up the handle for the localization
  9. local L = LibStub("AceLocale-3.0"):GetLocale("Gildam")
  10. local LibQTip = LibStub:GetLibrary("LibQTip-1.0")
  11.  
  12. --- Some local helper functions
  13. local _G = _G
  14. local tinsert, tremove, tsort, twipe = _G.table.insert, _G.table.remove, _G.table.sort, _G.table.wipe
  15. local pairs, ipairs = _G.pairs, _G.ipairs
  16.  
  17. local Gildam_backdrop = { -- Border gold
  18.     edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  19.     tile = false, tileSize = 8, edgeSize = 8,
  20.     insets = { left = 2, right = 2, top = 2, bottom = 2 }
  21. }  
  22.    
  23. local Gildam_TempPortraitAlphaMaskSmall = {
  24.     bgFile = "Interface\\CHARACTERFRAME\\TempPortraitAlphaMaskSmall", tile = false, tileSize = 20  
  25. }
  26.  
  27. --  Define the constants
  28. local GILDAM_GG_NO_RANKBUTTONS = 17         --  number of the guild ranks buttons
  29. local GILDAM_GR_NO_SCROLLBUTTONS = 16       --  number of scroll buttons for the Roster frame
  30. local GILDAM_GC_NO_SCROLLBUTTONS = 30       --  number of scroll buttons for the Character frame
  31. local GILDAM_MAX_LEVEL = 100                --  maximum level          
  32.  
  33. --  Table with the frame colors.
  34. local BBC = {
  35.     [1] = {["r"] = 1, ["g"] = 0.675, ["b"] = 0.125, ["a"] = 1}, -- gold
  36.     [2] = {["r"] = 1, ["g"] = 0, ["b"] = 0, ["a"] = 1},         -- red
  37.     [3] = {["r"] = 0, ["g"] = 1, ["b"] = 0, ["a"] = 1},         -- green
  38.     [4] = {["r"] = 0, ["g"] = 0, ["b"] = 1, ["a"] = 1},         -- blue
  39.     [5] = {["r"] = 1, ["g"] = 1, ["b"] = 0, ["a"] = 1},         -- yellow
  40.     [6] = {["r"] = 0.5, ["g"] = 0, ["b"] = 0.5, ["a"] = 1},     -- purple
  41.     [7] = {["r"] = 1, ["g"] = 0.65, ["b"] = 0, ["a"] = 1},      -- orange  
  42.     [8] = {["r"] = 0.75, ["g"] = 0.75, ["b"] = 0.75, ["a"] = 1} -- silver  
  43.     }
  44. --  Index for table with frame colors. Default is silver.
  45. local BBCi = 8 
  46.  
  47. --  Table  with the backgrounds textures.
  48. local BGT = {
  49.     [1] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\BakcgroundParchmentBlack"},
  50.     [2] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\BakcgroundParchmentBlood"},
  51.     [3] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\BakcgroundParchmentMoss"},
  52.     [4] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\BakcgroundParchmentRusty"}
  53.     }
  54. --  Index for table with background textures.
  55. local BGTi = 1
  56.  
  57. --  Default value for background alpha/transparency.
  58. local BGAi = 0.9
  59.  
  60. --  Table with the button border colors.
  61. local BBB = {
  62.     [1] = {["r"] = 1, ["g"] = 0.675, ["b"] = 0.125, ["a"] = 1}, -- gold
  63.     [2] = {["r"] = 0.75, ["g"] = 0.75, ["b"] = 0.75, ["a"] = 1} -- silver  
  64.     }
  65. --  Index for table with button colors. Default is gold.
  66. local BBBi = 1 
  67.  
  68. --  Table  with the button textures.
  69. local BBG = {
  70.     [1] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\ButtonBackGroundGreen"},
  71.     [2] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\ButtonBackGroundRed"},
  72.     [3] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\ButtonBackGroundBlue"},
  73.     [4] = {["t"] = "Interface\\AddOns\\Gildam\\Icons\\ButtonBackGroundPurple"} 
  74.     }
  75. --  Index for table with button textures.
  76. local BBGi = 1
  77.  
  78. --  Table  with the Character status textures.
  79. local CST = {
  80.     "Interface\\FriendsFrame\\StatusIcon-Online",
  81.     "Interface\\FriendsFrame\\StatusIcon-Away",
  82.     "Interface\\FriendsFrame\\StatusIcon-DnD",
  83.     "Interface\\FriendsFrame\\StatusIcon-Offline"
  84.     }
  85.    
  86. --  Table with the faction standings   
  87. local GFS = {
  88.     FACTION_STANDING_LABEL1,
  89.     FACTION_STANDING_LABEL2,
  90.     FACTION_STANDING_LABEL3,
  91.     FACTION_STANDING_LABEL4,
  92.     FACTION_STANDING_LABEL5,
  93.     FACTION_STANDING_LABEL6,
  94.     FACTION_STANDING_LABEL7,
  95.     FACTION_STANDING_LABEL8
  96.     }
  97.  
  98. -- The guild information fields we have stored.
  99. local Field = {
  100.     Name = 1,
  101.     Rank = 2,
  102.     RankIndex = 3,
  103.     Level = 4
  104.     Class = 5,
  105.     Zone = 6,
  106.     Note = 7,
  107.     OfficerNote = 8,
  108.     Online = 9,
  109.     Status = 10,
  110.     ClassConstant = 11,
  111.     Points = 12,
  112.     AchievementRank = 13,
  113.     IsMobile = 14,
  114.     SoR = 15,
  115.     RepStanding = 16,
  116.     LastOnline = 17,
  117.     FullName = 18,
  118.     Realm = 19 
  119. }
  120.  
  121. local Gildam_Class_order = {
  122.     WARRIOR = 1,
  123.     DEATHKNIGHT = 2,
  124.     PALADIN = 3,
  125.     MONK = 4,
  126.     PRIEST = 5,
  127.     SHAMAN = 6,
  128.     DRUID = 7,
  129.     ROGUE = 8,
  130.     MAGE = 9,
  131.     WARLOCK = 10,
  132.     HUNTER = 11,
  133. };
  134.  
  135. local RAID_CLASS_COLORS_hex = {}
  136. for k, v in pairs(RAID_CLASS_COLORS) do
  137.     RAID_CLASS_COLORS_hex[k] = ("|cff%02x%02x%02x"):format(v.r * 255, v.g * 255, v.b * 255)
  138. end
  139.  
  140. local Leader_Name = ""
  141.  
  142.  
  143. --------------------------------------------------------------------------------
  144. --  This is the Gildam Guild frame
  145. --------------------------------------------------------------------------------   
  146. function Gildam_Guild_Frame()
  147.     Gildam:Debug("Gildam_Guild_Frame")
  148.     local Gildam_GG = CreateFrame("Frame","Gildam_GG",Gildam_UI)
  149.     Gildam_GG:SetID(1)
  150.     Gildam_GG:SetPoint("TOP", "Gildam_UI", 0, -16)
  151.     Gildam_GG:SetPoint("BOTTOM", "Gildam_UI", 0, 16)
  152.     Gildam_GG:SetPoint("LEFT", "Gildam_UI", 16, 0)
  153.     Gildam_GG:SetPoint("RIGHT", "Gildam_UI", -16, 0)
  154.     Gildam_GG:SetBackdrop(Gildam_backdrop)
  155.     Gildam_GG:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  156.  
  157.     --  Define the Header with the Guild name
  158.     local Gildam_GG_Header = CreateFrame("Frame","Gildam_GG_Header",Gildam_GG)
  159.     Gildam_GG_Header:SetPoint("TOP", "Gildam_GG", 0, -16)
  160.     Gildam_GG_Header:SetPoint("BOTTOM", "Gildam_GG", "TOP", 0, -60)
  161.     Gildam_GG_Header:SetPoint("LEFT", "Gildam_GG", 16, 0)
  162.     Gildam_GG_Header:SetPoint("RIGHT", "Gildam_GG", -16, 0)
  163.     Gildam_GG_Header:SetBackdrop(Gildam_backdrop)
  164.     Gildam_GG_Header:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  165.    
  166.     --  Define the font string for the guild name
  167.     local Gildam_GG_Header_F1 = Gildam_GG_Header:CreateFontString("Gildam_GG_Header_F1", "ARTWORK", "GameFont_Gigantic")
  168.     Gildam_GG_Header_F1:SetAllPoints()
  169.  
  170.     --  Create the container frame for the guild banner.
  171.     local Gildam_GG_GBC = CreateFrame("Frame","Gildam_GG_GBC",Gildam_GG)
  172.     Gildam_GG_GBC:SetPoint("TOPLEFT", "Gildam_GG_Header", "BOTTOMLEFT" , 0, -16)
  173.     Gildam_GG_GBC:SetPoint("BOTTOMRIGHT", "Gildam_GG_Header", "BOTTOMLEFT" , 128, -144)
  174.     Gildam_GG_GBC:SetBackdrop(Gildam_backdrop)
  175.     Gildam_GG_GBC:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)   
  176.    
  177.     --  Create the "button" for the guild banner   
  178.     local Gildam_GG_GBB = CreateFrame("CheckButton","Gildam_GG_GBB",Gildam_GG_GBC,"SpellBookSkillLineTabTemplate") 
  179.     Gildam_GG_GBB:SetPoint("TOPLEFT", "Gildam_GG_GBC", 4, -4)
  180.     Gildam_GG_GBB:SetPoint("BOTTOMRIGHT", "Gildam_GG_GBC", -4, 4)  
  181.     Gildam_GG_GBB:SetScript("OnClick", nil)
  182.     Gildam_GG_GBB:SetScript("OnEnter", nil)
  183.     Gildam_GG_GBB:SetScript("OnLeave", nil)
  184.     Gildam_GG_GBB:SetHighlightTexture(nil)
  185.     Gildam_GG_GBB:SetCheckedTexture(nil)
  186.     Gildam_GG_GBB:Show()
  187.  
  188.     --  Create the frame for the faction banner
  189.     local Gildam_GG_GBF = CreateFrame("Frame","Gildam_GG_GBF",Gildam_GG)
  190.     Gildam_GG_GBF:SetPoint("TOPRIGHT", "Gildam_GG_Header", "BOTTOMRIGHT" , 0, -16)
  191.     Gildam_GG_GBF:SetPoint("BOTTOMLEFT", "Gildam_GG_Header", "BOTTOMRIGHT" , -128, -144)   
  192.     Gildam_GG_GBF:SetBackdrop(Gildam_backdrop)
  193.     Gildam_GG_GBF:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)   
  194.    
  195.     local Gildam_GG_GBF_T1 = Gildam_GG_GBF:CreateTexture("Gildam_GG_GBF_T1","ARTWORK")
  196.     Gildam_GG_GBF_T1:SetPoint("TOPLEFT", Gildam_GG_GBF, 4, -4);
  197.     Gildam_GG_GBF_T1:SetPoint("BOTTOMRIGHT", Gildam_GG_GBF, -4, 4) 
  198.    
  199.     --  Gets the players faction.
  200.     if private.Gildam_player_faction == "Horde" then
  201.         Gildam_GG_GBF_T1:SetTexture("Interface\\FriendsFrame\\PlusManz-Horde")
  202.     else   
  203.         Gildam_GG_GBF_T1:SetTexture("Interface\\FriendsFrame\\PlusManz-Alliance")
  204.     end    
  205.    
  206.     --  Create the frame for the guild info
  207.     local Gildam_GG_Info = CreateFrame("Frame","Gildam_GG_Info",Gildam_GG)
  208.     Gildam_GG_Info:SetPoint("TOPLEFT", "Gildam_GG_GBB", "TOPRIGHT" , 16, 2)
  209.     Gildam_GG_Info:SetPoint("BOTTOMRIGHT", "Gildam_GG_GBF", "BOTTOMLEFT" , -16, 0) 
  210.     Gildam_GG_Info:SetBackdrop(Gildam_backdrop)
  211.     Gildam_GG_Info:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  212.    
  213.     --  Define the font string for the guild info
  214.     local Gildam_GG_Info_F1 = Gildam_GG_Info:CreateFontString("Gildam_GG_Info_F1", "ARTWORK", "GameFontWhite")
  215.     Gildam_GG_Info_F1:SetPoint("TOP" ,"Gildam_GG_Info", 0, 0)
  216.     Gildam_GG_Info_F1:SetPoint("BOTTOM" ,"Gildam_GG_Info", "TOP", 0, -32)  
  217.     Gildam_GG_Info_F1:SetPoint("LEFT" ,"Gildam_GG_Info", 8, 0)
  218.     Gildam_GG_Info_F1:SetPoint("RIGHT" ,"Gildam_GG_Info", -8, 0)   
  219.    
  220.     local Gildam_GG_Info_F2 = Gildam_GG_Info:CreateFontString("Gildam_GG_Info_F2", "ARTWORK", "GameFontNormalSmall")
  221.     Gildam_GG_Info_F2:SetPoint("TOP" ,"Gildam_GG_Info", 0, -32)
  222.     Gildam_GG_Info_F2:SetPoint("BOTTOM" ,"Gildam_GG_Info", 0, -0)  
  223.     Gildam_GG_Info_F2:SetPoint("LEFT" ,"Gildam_GG_Info", 8, 0)
  224.     Gildam_GG_Info_F2:SetPoint("RIGHT" ,"Gildam_GG_Info", -8, 0)       
  225.  
  226.     --  Define the Container for the guild message of the day
  227.     local Gildam_GG_MOTD = CreateFrame("Frame","Gildam_GG_MOTD",Gildam_GG)
  228.     Gildam_GG_MOTD:SetPoint("TOP", "Gildam_GG_GBB", "BOTTOM", 0, -16)
  229.     Gildam_GG_MOTD:SetPoint("BOTTOM", "Gildam_GG_GBB", "BOTTOM", 0, -64)
  230.     Gildam_GG_MOTD:SetPoint("LEFT", "Gildam_GG", 16, 0)
  231.     Gildam_GG_MOTD:SetPoint("RIGHT", "Gildam_GG", -16, 0)
  232.     Gildam_GG_MOTD:SetBackdrop(Gildam_backdrop)
  233.     Gildam_GG_MOTD:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  234.  
  235.     --  Define the font string for the guild message of the day
  236.     local Gildam_GG_MOTD_F1 = Gildam_GG_MOTD:CreateFontString("Gildam_GG_MOTD_F1", "ARTWORK", "GameFontNormalSmall")
  237.     Gildam_GG_MOTD_F1:SetPoint("LEFT" ,"Gildam_GG_MOTD", 16, 0)
  238.     Gildam_GG_MOTD_F1:SetPoint("RIGHT" ,"Gildam_GG_MOTD", -16, 0)
  239.    
  240.     --  Define the font string for the GuildInfo
  241.     local Gildam_GG_MostOnline_F1 = Gildam_GG:CreateFontString("Gildam_GG_MostOnline_F1", "ARTWORK", "GameFontNormalSmall")
  242.     Gildam_GG_MostOnline_F1:SetPoint("BOTTOM", "Gildam_GG", 0, 4)  
  243.    
  244.     --  Define the leader frame
  245.     local Gildam_GG_Leader = CreateFrame("Frame","Gildam_GG_Leader",Gildam_GG)
  246.     Gildam_GG_Leader:SetPoint("TOPLEFT", "Gildam_GG_MOTD", "BOTTOMLEFT", 0, -16)
  247.     Gildam_GG_Leader:SetPoint("BOTTOMRIGHT", "Gildam_GG_MOTD", "BOTTOMLEFT", 96, -40)
  248.     Gildam_GG_Leader:SetPoint("LEFT", "Gildam_GG", 16, 0)
  249.     Gildam_GG_Leader:SetPoint("RIGHT", "Gildam_GG", "LEFT", 112, 0)
  250.     Gildam_GG_Leader:SetBackdrop(Gildam_backdrop)
  251.     Gildam_GG_Leader:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  252.  
  253.     --  Define the font string for the leader
  254.     local Gildam_GG_Leader_F1 = Gildam_GG_Leader:CreateFontString("Gildam_GG_Leader_F1", "ARTWORK", "GameFontWhite")
  255.     Gildam_GG_Leader_F1:SetAllPoints()
  256.     Gildam_GG_Leader_F1:SetText(LEADER)
  257.  
  258.     --  Define the leader name frame
  259.     local Gildam_GG_Leader_name = CreateFrame("Frame","Gildam_GG_Leader_name",Gildam_GG)
  260.     Gildam_GG_Leader_name:SetPoint("TOPLEFT", "Gildam_GG_Leader", "TOPRIGHT", 0, 0)
  261.     Gildam_GG_Leader_name:SetPoint("BOTTOMRIGHT", "Gildam_GG_Leader", "TOPRIGHT", 96, -24)
  262.     Gildam_GG_Leader_name:SetBackdrop(Gildam_backdrop)
  263.     Gildam_GG_Leader_name:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  264.  
  265.     --  Define the font string for the leader
  266.     local Gildam_GG_Leader_name_F1 = Gildam_GG_Leader_name:CreateFontString("Gildam_GG_Leader_name_F1", "ARTWORK", "GameFontNormal")
  267.     Gildam_GG_Leader_name_F1:SetAllPoints()
  268.     Gildam_GG_Leader_name_F1:SetText() 
  269.  
  270.     --  Define the Ranks frame
  271.     local Gildam_GG_Ranks = CreateFrame("Frame","Gildam_GG_Ranks",Gildam_GG)
  272.     Gildam_GG_Ranks:SetPoint("TOPLEFT", "Gildam_GG_Leader", "BOTTOMLEFT", 0, -16)
  273.     Gildam_GG_Ranks:SetPoint("BOTTOMRIGHT", "Gildam_GG_Leader", "BOTTOMLEFT", 96, -40)
  274.     Gildam_GG_Ranks:SetBackdrop(Gildam_backdrop)
  275.     Gildam_GG_Ranks:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  276.  
  277.     --  Define the font string for the ranks.
  278.     local Gildam_GG_Ranks_F1 = Gildam_GG_Ranks:CreateFontString("Gildam_GG_Ranks_F1", "ARTWORK", "GameFontWhite")
  279.     Gildam_GG_Ranks_F1:SetAllPoints()
  280.     Gildam_GG_Ranks_F1:SetText(GUILDCONTROL_GUILDRANKS)
  281.    
  282.     --  Define the container for the rank buttons.
  283.     local Gildam_GGRC2 = CreateFrame("Frame","Gildam_GGRC2",Gildam_GG)
  284.     Gildam_GGRC2:SetPoint("TOPLEFT", "Gildam_GG_Ranks", "TOPRIGHT", 0, -0)
  285.     Gildam_GGRC2:SetPoint("RIGHT", "Gildam_GG", "RIGHT", -16, 0)
  286.     Gildam_GGRC2:SetPoint("LEFT", "Gildam_GG", "LEFT", 0, 0)
  287.     Gildam_GGRC2:SetPoint("BOTTOM", "Gildam_GG_Ranks", "TOPRIGHT", 0, -24) 
  288.     Gildam_GGRC2:SetBackdrop(Gildam_backdrop)
  289.     Gildam_GGRC2:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  290.    
  291.     --  The table with text for the rank buttons.
  292.     local Gildam_GGRC2_text = {"#", "Gl", "Gs", "Ol", "Os", "P", "D", "Inv", "Rem", "Motd", "Epn", "Von", "Eon", "Info", "Repr", "Gold", "Event"}  
  293.    
  294.     --  Create the buttons that go inside the container for the rank buttons.
  295.     Gildam_GGRC2.list = {}
  296.     for i=1,GILDAM_GG_NO_RANKBUTTONS do
  297.         Gildam_GGRC2.list[i] = CreateFrame("Button",nil,Gildam_GGRC2)
  298.         Gildam_GGRC2.list[i]:SetSize(32,16)
  299.         Gildam_GGRC2.list[i]:SetPoint("TOPLEFT",Gildam_GGRC2,"TOPLEFT",(i-1)*36+16,-4)
  300.         Gildam_GGRC2.list[i]:Show()
  301.         Gildam_SetTooltip(Gildam_GGRC2.list[i], L["GGRC2_TT" .. tostring(i)])      
  302.  
  303.         Gildam_GGRC2.list[i].name1 = Gildam_GGRC2.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormalSmall")
  304.         Gildam_GGRC2.list[i].name1:SetSize(32,16)
  305.         Gildam_GGRC2.list[i].name1:SetPoint("CENTER", Gildam_GGRC2.list[i])
  306.         Gildam_GGRC2.list[i].name1:SetText(Gildam_GGRC2_text[i])
  307.     end    
  308.        
  309.     --  Define the container frame for the ranks
  310.     local Gildam_GGRC1 = CreateFrame("Frame","Gildam_GGRC1",Gildam_GG)
  311.     Gildam_GGRC1:SetPoint("TOPLEFT", "Gildam_GG_Ranks", "BOTTOMLEFT", 0, 0)
  312.     Gildam_GGRC1:SetPoint("BOTTOMRIGHT", "Gildam_GG", "BOTTOMRIGHT", -16, 16)
  313.     Gildam_GGRC1:SetBackdrop(Gildam_backdrop)
  314.     Gildam_GGRC1:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  315.    
  316.     --  Create the buttons that go inside the container frame for the ranks
  317.     Gildam_GGRC1.list = {}
  318.     for i=1,GuildControlGetNumRanks() do
  319.         Gildam_GGRC1.list[i] = CreateFrame("Button",nil,Gildam_GGRC1)
  320.         Gildam_GGRC1.list[i]:SetSize(400,16)
  321.         Gildam_GGRC1.list[i]:SetPoint("TOPLEFT",Gildam_GGRC1,"TOPLEFT",8,(i-1)*-16-4)
  322.         Gildam_GGRC1.list[i]:Show()
  323.  
  324.         Gildam_GGRC1.list[i].name1 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  325.         Gildam_GGRC1.list[i].name1:SetSize(100,16)
  326.         Gildam_GGRC1.list[i].name1:SetPoint("LEFT", Gildam_GGRC1.list[i])
  327.         Gildam_GGRC1.list[i].name1:SetJustifyH("LEFT")             
  328.  
  329.         Gildam_GGRC1.list[i].name2 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  330.         Gildam_GGRC1.list[i].name2:SetSize(32,16)
  331.         Gildam_GGRC1.list[i].name2:SetPoint("LEFT", Gildam_GGRC1.list[i].name1, "RIGHT", 4, 0) 
  332.  
  333.         Gildam_GGRC1.list[i].name3 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  334.         Gildam_GGRC1.list[i].name3:SetSize(32,16)
  335.         Gildam_GGRC1.list[i].name3:SetPoint("LEFT", Gildam_GGRC1.list[i].name2, "RIGHT", 4, 0) 
  336.  
  337.         Gildam_GGRC1.list[i].name4 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  338.         Gildam_GGRC1.list[i].name4:SetSize(32,16)
  339.         Gildam_GGRC1.list[i].name4:SetPoint("LEFT", Gildam_GGRC1.list[i].name3, "RIGHT", 4, 0)     
  340.  
  341.         Gildam_GGRC1.list[i].name5 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  342.         Gildam_GGRC1.list[i].name5:SetSize(32,16)
  343.         Gildam_GGRC1.list[i].name5:SetPoint("LEFT", Gildam_GGRC1.list[i].name4, "RIGHT", 4, 0) 
  344.  
  345.         Gildam_GGRC1.list[i].name6 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  346.         Gildam_GGRC1.list[i].name6:SetSize(32,16)
  347.         Gildam_GGRC1.list[i].name6:SetPoint("LEFT", Gildam_GGRC1.list[i].name5, "RIGHT", 4, 0) 
  348.  
  349.         Gildam_GGRC1.list[i].name7 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  350.         Gildam_GGRC1.list[i].name7:SetSize(32,16)
  351.         Gildam_GGRC1.list[i].name7:SetPoint("LEFT", Gildam_GGRC1.list[i].name6, "RIGHT", 4, 0)         
  352.  
  353.         Gildam_GGRC1.list[i].name8 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  354.         Gildam_GGRC1.list[i].name8:SetSize(32,16)
  355.         Gildam_GGRC1.list[i].name8:SetPoint("LEFT", Gildam_GGRC1.list[i].name7, "RIGHT", 4, 0) 
  356.  
  357.         Gildam_GGRC1.list[i].name9 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  358.         Gildam_GGRC1.list[i].name9:SetSize(32,16)
  359.         Gildam_GGRC1.list[i].name9:SetPoint("LEFT", Gildam_GGRC1.list[i].name8, "RIGHT", 4, 0)         
  360.  
  361.         Gildam_GGRC1.list[i].name10 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  362.         Gildam_GGRC1.list[i].name10:SetSize(32,16)
  363.         Gildam_GGRC1.list[i].name10:SetPoint("LEFT", Gildam_GGRC1.list[i].name9, "RIGHT", 4, 0)        
  364.  
  365.         Gildam_GGRC1.list[i].name11 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  366.         Gildam_GGRC1.list[i].name11:SetSize(32,16)
  367.         Gildam_GGRC1.list[i].name11:SetPoint("LEFT", Gildam_GGRC1.list[i].name10, "RIGHT", 4, 0)   
  368.        
  369.         Gildam_GGRC1.list[i].name12 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  370.         Gildam_GGRC1.list[i].name12:SetSize(32,16)
  371.         Gildam_GGRC1.list[i].name12:SetPoint("LEFT", Gildam_GGRC1.list[i].name11, "RIGHT", 4, 0)   
  372.        
  373.         Gildam_GGRC1.list[i].name13 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  374.         Gildam_GGRC1.list[i].name13:SetSize(32,16)
  375.         Gildam_GGRC1.list[i].name13:SetPoint("LEFT", Gildam_GGRC1.list[i].name12, "RIGHT", 4, 0)   
  376.  
  377.         Gildam_GGRC1.list[i].name14 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  378.         Gildam_GGRC1.list[i].name14:SetSize(32,16)
  379.         Gildam_GGRC1.list[i].name14:SetPoint("LEFT", Gildam_GGRC1.list[i].name13, "RIGHT", 4, 0)   
  380.  
  381.         Gildam_GGRC1.list[i].name15 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  382.         Gildam_GGRC1.list[i].name15:SetSize(32,16)
  383.         Gildam_GGRC1.list[i].name15:SetPoint("LEFT", Gildam_GGRC1.list[i].name14, "RIGHT", 4, 0)   
  384.        
  385.         Gildam_GGRC1.list[i].name16 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  386.         Gildam_GGRC1.list[i].name16:SetSize(32,16)
  387.         Gildam_GGRC1.list[i].name16:SetPoint("LEFT", Gildam_GGRC1.list[i].name15, "RIGHT", 4, 0)   
  388.  
  389.         Gildam_GGRC1.list[i].name17 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  390.         Gildam_GGRC1.list[i].name17:SetSize(32,16)
  391.         Gildam_GGRC1.list[i].name17:SetPoint("LEFT", Gildam_GGRC1.list[i].name16, "RIGHT", 4, 0)   
  392.  
  393.         Gildam_GGRC1.list[i].name18 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal")
  394.         Gildam_GGRC1.list[i].name18:SetSize(32,16)
  395.         Gildam_GGRC1.list[i].name18:SetPoint("LEFT", Gildam_GGRC1.list[i].name17, "RIGHT", 4, 0)   
  396.     end
  397.    
  398.     Gildam_GG:Hide()
  399. end
  400.  
  401.  
  402. -------------------------------------------------------------------------------
  403. --  Handle the Guild Tab
  404. -------------------------------------------------------------------------------
  405. function Gildam_GG_Update()
  406.     Gildam:Debug("Gildam_GG_Update")
  407.    
  408.     Gildam_Use_Database_Values_G()
  409.    
  410.     --  Set the UI texture, alpha/transparency  and border color in case they have been changed.
  411.     Gildam_UI_T:SetTexture(BGT[BGTi].t)
  412.     Gildam_UI_T:SetAlpha(BGAi) 
  413.     Gildam_UI:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  414.    
  415.     --  Show the guild banner. 
  416.     Gildam_GG_GBB.TabardEmblem:SetSize(120, 120)
  417.     Gildam_GG_GBB.TabardIconFrame:SetSize(120,120) 
  418.     Gildam_GG_GBB:SetNormalTexture("Interface\\SpellBook\\GuildSpellbooktabBG");
  419.     Gildam_GG_GBB.TabardEmblem:Show();
  420.     Gildam_GG_GBB.TabardIconFrame:Show();
  421.     SetLargeGuildTabardTextures("player", Gildam_GG_GBB.TabardEmblem, Gildam_GG_GBB:GetNormalTexture(), Gildam_GG_GBB.TabardIconFrame);
  422.  
  423.     --  Set the button border color and background color in case they have been changed.   
  424.     Gildam_Close:SetBackdropBorderColor(BBB[(BBBi)].r, BBB[(BBBi)].g, BBB[(BBBi)].b, BBB[(BBBi)].a)
  425.     Gildam_CloseT:SetTexture(BBG[BBGi].t)  
  426.    
  427.     --  Set the Guild frames color again in case they have been changed.   
  428.     Gildam_GG:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  429.     Gildam_GG_Header:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  430.     Gildam_GG_GBC:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  431.     Gildam_GG_GBF:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)   
  432.     Gildam_GG_Info:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)  
  433.     Gildam_GG_MOTD:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)  
  434.     Gildam_GG_Leader:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  435.     Gildam_GG_Leader_name:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  436.     Gildam_GG_Ranks:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  437.     Gildam_GGRC2:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)    
  438.     Gildam_GGRC1:SetBackdropBorderColor(BBC[(BBCi)].r, BBC[(BBCi)].g, BBC[(BBCi)].b, BBC[(BBCi)].a)
  439.  
  440.     --  Set the guild info.
  441.     Gildam_GG_Info_F1:SetText(GUILD_INFORMATION)   
  442.     Gildam_GG_Info_F2:SetText(GetGuildInfoText())
  443.    
  444.     --  Set the message of the day.
  445.     Gildam_GG_MOTD_F1:SetText(format(GUILD_MOTD_TEMPLATE, GetGuildRosterMOTD()))
  446.  
  447.     --  Set guild name.
  448.     if private.Gildam_player_faction == "Horde" then
  449.         Gildam_GG_Header_F1:SetText(Gildam_red(GetGuildInfo("player")))
  450.     else   
  451.         Gildam_GG_Header_F1:SetText(Gildam_blue(GetGuildInfo("player")))
  452.     end
  453.    
  454.     --  Set GuildInfo text.
  455.     Gildam_GG_GuildInfo_F1:SetText(private.Gildam_GuildInfo_string)
  456.    
  457.     --  Set Most players online text.
  458.     Gildam_GG_MostOnline_F1:SetText(format(L["Most players online: %d at %s"], private.GuildDB.most_players_online,
  459.         format(date("%A, %B %d %Y, %H:%M", private.GuildDB.most_players_online_time))))
  460.  
  461.     --  Guild leader name.
  462.     Gildam_Browse_Roster()
  463.     Gildam_GG_Leader_name_F1:SetText(Leader_Name)
  464.  
  465.     --  Set the names of the ranks 
  466.     for i = 1, GuildControlGetNumRanks() do
  467.         if GuildControlGetRankName(i) ~= nil then
  468.             Gildam_GGRC1.list[i].name1:SetText(GuildControlGetRankName(i))
  469.             Gildam_GGRC1.list[i].name2:SetText(GetNumMembersInRank(i))
  470.             GuildControlSetRank(i)
  471.             local guildchat_listen, guildchat_speak, officerchat_listen, officerchat_speak, promote, demote,
  472.                 invite_member, remove_member, set_motd, edit_public_note, view_officer_note, edit_officer_note,
  473.                 modify_guild_info, _, withdraw_repair, withdraw_gold, create_guild_event = GuildControlGetRankFlags(); 
  474.             if guildchat_listen then
  475.                 Gildam_GGRC1.list[i].name3:SetText(Gildam_green(YES))
  476.             else
  477.                 Gildam_GGRC1.list[i].name3:SetText(Gildam_red(NO))
  478.             end
  479.             if  guildchat_speak then
  480.                 Gildam_GGRC1.list[i].name4:SetText(Gildam_green(YES))
  481.             else
  482.                 Gildam_GGRC1.list[i].name4:SetText(Gildam_red(NO))
  483.             end
  484.                 if officerchat_listen then
  485.                 Gildam_GGRC1.list[i].name5:SetText(Gildam_green(YES))
  486.             else
  487.                 Gildam_GGRC1.list[i].name5:SetText(Gildam_red(NO))
  488.             end
  489.             if  officerchat_speak then
  490.                 Gildam_GGRC1.list[i].name6:SetText(Gildam_green(YES))
  491.             else
  492.                 Gildam_GGRC1.list[i].name6:SetText(Gildam_red(NO))
  493.             end        
  494.             if promote then
  495.                 Gildam_GGRC1.list[i].name7:SetText(Gildam_green(YES))
  496.             else
  497.                 Gildam_GGRC1.list[i].name7:SetText(Gildam_red(NO))
  498.             end
  499.             if demote then
  500.                 Gildam_GGRC1.list[i].name8:SetText(Gildam_green(YES))
  501.             else
  502.                 Gildam_GGRC1.list[i].name8:SetText(Gildam_red(NO))
  503.             end        
  504.             if invite_member then
  505.                 Gildam_GGRC1.list[i].name9:SetText(Gildam_green(YES))
  506.             else
  507.                 Gildam_GGRC1.list[i].name9:SetText(Gildam_red(NO))
  508.             end    
  509.             if remove_member then
  510.                 Gildam_GGRC1.list[i].name10:SetText(Gildam_green(YES))
  511.             else
  512.                 Gildam_GGRC1.list[i].name10:SetText(Gildam_red(NO))
  513.             end    
  514.             if set_motd then
  515.                 Gildam_GGRC1.list[i].name11:SetText(Gildam_green(YES))
  516.             else
  517.                 Gildam_GGRC1.list[i].name11:SetText(Gildam_red(NO))
  518.             end
  519.             if edit_public_note then
  520.                 Gildam_GGRC1.list[i].name12:SetText(Gildam_green(YES))
  521.             else
  522.                 Gildam_GGRC1.list[i].name12:SetText(Gildam_red(NO))
  523.             end
  524.             if view_officer_note then
  525.                 Gildam_GGRC1.list[i].name13:SetText(Gildam_green(YES))
  526.             else
  527.                 Gildam_GGRC1.list[i].name13:SetText(Gildam_red(NO))
  528.             end
  529.             if edit_officer_note then
  530.                 Gildam_GGRC1.list[i].name14:SetText(Gildam_green(YES))
  531.             else
  532.                 Gildam_GGRC1.list[i].name14:SetText(Gildam_red(NO))
  533.             end        
  534.             if modify_guild_info then
  535.                 Gildam_GGRC1.list[i].name15:SetText(Gildam_green(YES))
  536.             else
  537.                 Gildam_GGRC1.list[i].name15:SetText(Gildam_red(NO))
  538.             end
  539.             if withdraw_repair then
  540.                 Gildam_GGRC1.list[i].name16:SetText(Gildam_green(YES))
  541.             else
  542.                 Gildam_GGRC1.list[i].name16:SetText(Gildam_red(NO))
  543.             end
  544.             if withdraw_gold then
  545.                 Gildam_GGRC1.list[i].name17:SetText(Gildam_green(YES))
  546.             else
  547.                 Gildam_GGRC1.list[i].name17:SetText(Gildam_red(NO))
  548.             end
  549.             if create_guild_event then
  550.                 Gildam_GGRC1.list[i].name18:SetText(Gildam_green(YES))
  551.             else
  552.                 Gildam_GGRC1.list[i].name18:SetText(Gildam_red(NO))
  553.             end
  554.         end        
  555.     end    
  556. end
  557.  
  558.  
  559. -------------------------------------------------------------------------------
  560. --  Browse the guild roster and get the desired information
  561. -------------------------------------------------------------------------------
  562. function Gildam_Browse_Roster()
  563.     Gildam:Debug("Gildam_Browse_Roster")
  564.     for idx = 1, #private.GuildDB.roster do
  565.         local info = private.GuildDB.roster[idx]
  566.         if info[Field.RankIndex] == 0 then
  567.             Leader_Name = info[Field.Name]
  568.         end
  569.     end
  570. end
  571.  
  572.  
  573. -------------------------------------------------------------------------------
  574.     -- Use the database values.
  575. -------------------------------------------------------------------------------
  576. function Gildam_Use_Database_Values_G()
  577.     BBCi = addon.db.profile.frameColor
  578.     BGTi = addon.db.profile.frameTexture   
  579.     BGAi = addon.db.profile.alphaBG
  580.     BBBi = addon.db.profile.buttonBorder
  581.     BBGi = addon.db.profile.buttonColor
  582. end
__________________
Better to fail then never have tried at all.
  Reply With Quote
10-07-15, 04:08 AM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It would appear that Gildam_GG_Update() is either being called before Gildam_Guild_Frame(), or GuildControlGetNumRanks() isn't returning accurate data when Gildam_Guild_Frame() is called.

They're being called from outside of this file so I can't tell what order they're being called in.

Just changing "if GuildControlGetRankName(i) ~= nil then" to "if Gildam_GGRC1.list and Gildam_GGRC1.list[i] then" would probably prevent the error, but it would be better to make sure the functions are being called in the correct order.

Last edited by semlar : 10-07-15 at 04:14 AM.
  Reply With Quote
10-07-15, 01:58 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Originally Posted by Yukyuk View Post
And is there a better way to post almost 600 lines of code?
You could use a site like Pastebin.com or include your addon temporarily as an attachment to your post. You can manage your attachments in User Control Panel » Attachments.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-09-15, 01:40 PM   #6
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Log database.

Checked to flow of my addon and as far as I can tell everything is called in the correct order.

But I will create a log database inside the addon and log the function calls.
Then when the error I happens again I can check to see if the flow is different.
__________________
Better to fail then never have tried at all.
  Reply With Quote
10-09-15, 01:57 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
My guess is Gildam_Guild_Frame() is being called before the game gets any info about the guild. By the time Gildam_GG_Update() gets called, there is guild info, but none of the frames were created from the previous function. You should also keep in mind the number of ranks and details can change while the addon is running.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-09-15 at 02:00 PM.
  Reply With Quote
10-11-15, 07:45 AM   #8
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Found?

Think I found the error.
Further testing will see if I am right.

And it was indeed a function that was called too soon.
__________________
Better to fail then never have tried at all.
  Reply With Quote
10-12-15, 04:05 PM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
What you probably should do is offload the creation of the list items to a check in the update function. This will not only fix the problem of the guild rank count being zero on creation, but cover you if the guildmaster decides to add/delete a rank while the addon is running.

In your creation function, just leave this line:
Lua Code:
  1. Gildam_GGRC1.list={};

For the update function, put this in:
Lua Code:
  1. --  Strings for permissions (put this somewhere at the top of the script)
  2. local Gildam_YES="|cff00ff00"..YES.."|r";
  3. local Gildam_NO="|cffff0000"..NO.."|r";
  4.  
  5. --  This goes in your update function
  6. local numranks=GuildControlGetNumRanks();
  7. for i=#Gildam_GGRC1.list+1,numranks do-- This loop won't run if it doesn't need to create new entries (start would be greater than end)
  8.     local frame=CreateFrame("Button",nil,Gildam_GGRC1);
  9.     frame:SetSize(400,16);
  10.     frame:SetPoint("TOPLEFT",8,(i-1)*-16-4);
  11.  
  12.     frame.name1 = Gildam_GGRC1.list[i]:CreateFontString(nil,"ARTWORK","GameFontNormal");
  13.     frame.name1:SetSize(100,16);
  14.     frame.name1:SetPoint("LEFT");
  15.     frame.name1:SetJustifyH("LEFT");
  16.  
  17. --  The rest of these can be done with a loop and some math
  18.     for j=2,18 do
  19.         local fontstring=frame:CreateFontString(nil,"ARTWORK","GameFontNormal");
  20.         fontstring:SetSize(32,16);
  21.         fontstring:SetPoint("LEFT",i*36+32,0);
  22.         frame["name"..j]=fontstring;
  23.     end
  24.     Gildam_GGRC1.list[i]=frame;
  25. end
  26.  
  27. for i,j in ipairs(Gildam_GGRC1.list) do--   We need to iterate though all frames to update the entire set
  28.     if i>numranks then
  29.         j:Hide();-- Hide ranks that have been removed
  30.     else
  31.         j:Show();
  32.  
  33. --      Update rank info
  34.         j.name1:SetText(GuildControlGetRankName(i))
  35.         j.name2:SetText(GetNumMembersInRank(i))
  36.  
  37.         GuildControlSetRank(i)
  38.         local guildchat_listen, guildchat_speak, officerchat_listen, officerchat_speak, promote, demote,
  39.             invite_member, remove_member, set_motd, edit_public_note, view_officer_note, edit_officer_note,
  40.             modify_guild_info, _, withdraw_repair, withdraw_gold, create_guild_event = GuildControlGetRankFlags();  
  41.  
  42.         j.name3:SetText(guildchat_listen    and Gildam_YES or Gildam_NO);
  43.         j.name4:SetText(guildchat_speak     and Gildam_YES or Gildam_NO);
  44.         j.name5:SetText(officerchat_listen  and Gildam_YES or Gildam_NO);
  45.         j.name6:SetText(officerchat_speak   and Gildam_YES or Gildam_NO);
  46.         j.name7:SetText(promote             and Gildam_YES or Gildam_NO);
  47.         j.name8:SetText(demote              and Gildam_YES or Gildam_NO);
  48.         j.name9:SetText(invite_member       and Gildam_YES or Gildam_NO);
  49.         j.name10:SetText(remove_member      and Gildam_YES or Gildam_NO);
  50.         j.name11:SetText(set_motd           and Gildam_YES or Gildam_NO);
  51.         j.name12:SetText(edit_public_note   and Gildam_YES or Gildam_NO);
  52.         j.name13:SetText(view_officer_note  and Gildam_YES or Gildam_NO);
  53.         j.name14:SetText(edit_officer_note  and Gildam_YES or Gildam_NO);
  54.         j.name15:SetText(modify_guild_info  and Gildam_YES or Gildam_NO);
  55.         j.name16:SetText(withdraw_repair    and Gildam_YES or Gildam_NO);
  56.         j.name17:SetText(withdraw_gold      and Gildam_YES or Gildam_NO);
  57.         j.name18:SetText(create_guild_event and Gildam_YES or Gildam_NO);
  58.     end
  59. end



For future reference, when you run multiple lines of code on an object in a table, you should cache the object in a local and reference that instead. This would reduce the number of indexing operations you're executing and make your code run much more efficiently overall. There are a couple examples of this in the code I posted above.

You should also avoid calling functions or doing any operations to generate a constant value after initialization. An example of where this happens is where calls were made to Gildam_green(YES) and Gildam_red(NO). Constants should be made as upvalues as demonstrated above with Gildam_YES and Gildam_NO.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-12-15 at 05:55 PM.
  Reply With Quote
10-13-15, 11:37 AM   #10
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Great advice.

Great advice SDPhantom.
Will adjust the code.

And will see if this can be used in other parts of Gildam.
__________________
Better to fail then never have tried at all.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Lua error on GuildControlGetRankName?


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