View Single Post
03-09-21, 03:45 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
What I meant about changing the code to use return instead of break would look like this:
Lua Code:
  1. if self:SetWatchedFactionByFactionID(factionID) then
  2.     return
  3. end
If I make that change, it might work, but I feel like I am trying to write code until something sticks; therefore I am asking for more eyes to find anything that I missed.

Oh, and I forgot as part of "show the code", here is the section that sets the reputation bar by factionID.
Lua Code:
  1. -------------------- Reputation code starts here --------------------
  2. local repsCollapsed = {} -- Obey user's settings about headers opened or closed
  3. -- Open all faction headers
  4. function RepByZone:OpenAllFactionHeaders()
  5.     local i = 1
  6.     while i <= GetNumFactions() do
  7.         local name, _, _, _, _, _, _, _, isHeader, isCollapsed = GetFactionInfo(i)
  8.         if isHeader then
  9.             repsCollapsed[name] = isCollapsed
  10.             if name == FACTION_INACTIVE then
  11.                 if not isCollapsed then
  12.                     CollapseFactionHeader(i)
  13.                 end
  14.                 break
  15.             elseif isCollapsed then
  16.                 ExpandFactionHeader(i)
  17.             end
  18.         end
  19.         i = i + 1
  20.     end
  21. end
  22.  
  23. -- Close all faction headers
  24. function RepByZone:CloseAllFactionHeaders()
  25.     local i = 1
  26.     while i <= GetNumFactions() do
  27.         local name, _, _, _, _, _, _, _, isHeader, isCollapsed = GetFactionInfo(i)
  28.         if isHeader then
  29.             if isCollapsed and not repsCollapsed[name] then
  30.                 ExpandFactionHeader(i)
  31.             elseif repsCollapsed[name] and not isCollapsed then
  32.                 CollapseFactionHeader(i)
  33.             end
  34.         end
  35.         i = i + 1
  36.     end
  37.     wipe(repsCollapsed)
  38. end
  39.  
  40. function RepByZone:GetAllFactions()
  41.     -- Will not return factions the user has marked as inactive
  42.     self:OpenAllFactionHeaders()
  43.     local factionList = {}
  44.  
  45.     for i = 1, GetNumFactions() do
  46.         local name, _, _, _, _, _, _, _, isHeader, _, _, _, _, factionID = GetFactionInfo(i)
  47.         if not isHeader then
  48.             factionList[factionID] = name
  49.         end
  50.     end
  51.     factionList["0-none"] = NONE
  52.  
  53.     self:CloseAllFactionHeaders()
  54.     return factionList
  55. end
  56.  
  57. -- Blizzard sets watched faction by index, not by factionID so create our own API
  58. function RepByZone:SetWatchedFactionByFactionID(id)
  59.     if type(id) ~= "number" then return end
  60.  
  61.     self:OpenAllFactionHeaders()
  62.     for i = 1, GetNumFactions() do
  63.         local name, _, standingID, _, _, _, _, _, isHeader, _, _, isWatched, _, factionID = GetFactionInfo(i)
  64.         if id == factionID then
  65.             if not isWatched then
  66.                 SetWatchedFactionIndex(i)
  67.                 if db.verbose then
  68.                     self:Print(L["Now watching %s"]:format(name))
  69.                 end
  70.             end
  71.             self:CloseAllFactionHeaders()
  72.             return name, id
  73.         end
  74.     end
  75.     self:CloseAllFactionHeaders()
  76. end

Last edited by myrroddin : 03-09-21 at 03:48 PM. Reason: More "show the code"
  Reply With Quote