Quantcast WoWInterface - View Single Post - [Classic] GetNumFactions() not getting past index 1
View Single Post
10-14-19, 09:09 PM   #1
A Pyroguard Emberseer
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,085
[Classic] GetNumFactions() not getting past index 1

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:
  1. -- Blizzard sets watched faction by index, not by factionID so create our own API
  2. function RepByZone:SetWatchedFactionByFactionID(id)
  3.     if type(id) == "table" then id = tonumber(id) end
  4.     if type(id) ~= "number" then return end
  6.     self:OpenAllFactionHeaders()
  7.     for i = 1, GetNumFactions() do
  8.         local name, _, standingID, _, _, _, _, _, isHeader, _, _, isWatched, _, factionID = GetFactionInfoByID(id)
  9.         if id == factionID then
  10.             self:Print("DEBUG: SetWatchedFactionByFactionID name:", name)
  11.             self:Print("DEBUG: SetWatchedFactionByFactionID index:", i)
  12.             if not isWatched then
  13.                 SetWatchedFactionIndex(i)
  14.             end
  15.             self:CloseAllFactionHeaders()
  16.             return name, id
  17.         else
  18.             break
  19.         end
  20.     end
  21.     self:CloseAllFactionHeaders()
  22. end

Last edited by myrroddin : 10-14-19 at 09:12 PM. Reason: Noted factionID for Stormwind, and that finding the factionID code is working
  Reply With Quote