I have a function that sets the watched faction by factionID, seeing how Blizzard's SetWatchedFactionIndex() only works from 1 to GetNumFactions() I had to create a function.
However, my code isn't advancing properly past index 1, "Alliance" in my testbed. Oddly, the test prints are getting the correct factionID and name. I am missing something, and can't spot it.
I don't think it matters that this code is for Classic, by all accounts it should work for Retail as well, except my comparison tables that return the factionID are based on Classic's UIMapIDs, which are not the same for both versions.
The first print's output is "Stormwind" because that is where my toon is, while the second's output is "1", which is not correct. Based on my low level and lack of world exploration, the index should be "5" for Stormwind.
Further testing from other print outputs does indicate that the factionID 1453 is correct, and matching for Stormwind.
Lua Code:
-- Blizzard sets watched faction by index, not by factionID so create our own API
function RepByZone:SetWatchedFactionByFactionID(id)
if type(id) == "table" then id = tonumber(id) end
if type(id) ~= "number" then return end
self:OpenAllFactionHeaders()
for i = 1, GetNumFactions() do
local name, _, standingID, _, _, _, _, _, isHeader, _, _, isWatched, _, factionID = GetFactionInfoByID(id)
if id == factionID then
self:Print("DEBUG: SetWatchedFactionByFactionID name:", name)
self:Print("DEBUG: SetWatchedFactionByFactionID index:", i)
if not isWatched then
SetWatchedFactionIndex(i)
end
self:CloseAllFactionHeaders()
return name, id
else
break
end
end
self:CloseAllFactionHeaders()
end