What I meant about changing the code to use return instead of break would look like this:
Lua Code:
if self:SetWatchedFactionByFactionID(factionID) then
return
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:
-------------------- Reputation code starts here --------------------
local repsCollapsed = {} -- Obey user's settings about headers opened or closed
-- Open all faction headers
function RepByZone:OpenAllFactionHeaders()
local i = 1
while i <= GetNumFactions() do
local name, _, _, _, _, _, _, _, isHeader, isCollapsed = GetFactionInfo(i)
if isHeader then
repsCollapsed[name] = isCollapsed
if name == FACTION_INACTIVE then
if not isCollapsed then
CollapseFactionHeader(i)
end
break
elseif isCollapsed then
ExpandFactionHeader(i)
end
end
i = i + 1
end
end
-- Close all faction headers
function RepByZone:CloseAllFactionHeaders()
local i = 1
while i <= GetNumFactions() do
local name, _, _, _, _, _, _, _, isHeader, isCollapsed = GetFactionInfo(i)
if isHeader then
if isCollapsed and not repsCollapsed[name] then
ExpandFactionHeader(i)
elseif repsCollapsed[name] and not isCollapsed then
CollapseFactionHeader(i)
end
end
i = i + 1
end
wipe(repsCollapsed)
end
function RepByZone:GetAllFactions()
-- Will not return factions the user has marked as inactive
self:OpenAllFactionHeaders()
local factionList = {}
for i = 1, GetNumFactions() do
local name, _, _, _, _, _, _, _, isHeader, _, _, _, _, factionID = GetFactionInfo(i)
if not isHeader then
factionList[factionID] = name
end
end
factionList["0-none"] = NONE
self:CloseAllFactionHeaders()
return factionList
end
-- Blizzard sets watched faction by index, not by factionID so create our own API
function RepByZone:SetWatchedFactionByFactionID(id)
if type(id) ~= "number" then return end
self:OpenAllFactionHeaders()
for i = 1, GetNumFactions() do
local name, _, standingID, _, _, _, _, _, isHeader, _, _, isWatched, _, factionID = GetFactionInfo(i)
if id == factionID then
if not isWatched then
SetWatchedFactionIndex(i)
if db.verbose then
self:Print(L["Now watching %s"]:format(name))
end
end
self:CloseAllFactionHeaders()
return name, id
end
end
self:CloseAllFactionHeaders()
end