Okay, this is bizzare; I was wrong: it isn't WoD zones, it is the final check to assign world zone data. No matter if I use:
Code:
if type(watchedFactionID) ~= "number" then ...
Or if I use
Code:
if not watchedFactionID then ...
Both of these fail, or at least are somehow assigning a value of 0 or nil to
watchedFactionID. I have no clue why either of those if statements are behaving like that.
Here is my updated function SwitchedZones() with the faulty if statement on line 82 below.
Lua Code:
-- Player switched zones, subzones, or instances, set watched faction
function RepByZone:SwitchedZones(event)
if not db.enabled then return end -- Exit if the addon is disabled
-- Possible zoning issues, exit out unless we have valid map data
local uiMapID = C_Map.GetBestMapForUnit("player")
if not uiMapID then return end
if isOnTaxi then
if not db.watchOnTaxi then
-- On taxi but don't switch
return
end
end
-- Some data may not be available because of the specialty zone functions, get something until a full data update refreshes things
instancesAndFactions = instancesAndFactions or self:InstancesAndFactionList()
zonesAndFactions = zonesAndFactions or self:ZoneAndFactionList()
subZonesAndFactions = subZonesAndFactions or self:SubZonesAndFactionsList()
if event == "BODYGUARD_UPDATED" then
-- This is a custom event
bodyguardRepID = self:GetActiveBodyguardRepID()
else
-- bodyguardRepID might still be nil if there is no bodyguard
bodyguardRepID = bodyguardRepID or self:GetActiveBodyguardRepID()
end
-- Set up variables
local _, watchedFactionID, factionName, isWatched
local hasDungeonTabard = false
local inInstance, instanceType = IsInInstance()
local whichInstanceID = inInstance and select(8, GetInstanceInfo())
local parentMapID = C_Map.GetMapInfo(uiMapID).parentMapID
local subZone = GetMinimapZoneText()
local isWoDZone = self.WoDFollowerZones[uiMapID] or (self.WoDFollowerZones[uiMapID] == nil and self.WoDFollowerZones[parentMapID])
-- Apply instance reputations. Garrisons return false for inInstance and "party" for instanceType, which is good, we can filter them out
if inInstance and instanceType == "party" then
hasDungeonTabard = false
-- Certain dungeons do not benefit from tabards
if self.tabardExemptDungeons[whichInstanceID] then
return
end
-- Process faction tabards
if db.useFactionTabards then
if tabardID then
watchedFactionID = tabardID
hasDungeonTabard = true
end
else
-- We aren't watching faction tabards
hasDungeonTabard = false
end
else
-- We aren't in a party
hasDungeonTabard = false
end
-- We aren't in an instance that supports tabards or we aren't watching tabards in the dungeon
if inInstance and not hasDungeonTabard then
watchedFactionID = instancesAndFactions[whichInstanceID]
end
-- Override in WoD zones only if a bodyguard exists
if isWoDZone and bodyguardRepID then
watchedFactionID = bodyguardRepID
end
-- Process subzones
if db.watchSubZones then
-- Don't loop through subzones if the player is watching a bodyguard rep
if isWoDZone and bodyguardRepID then return end
-- Battlegrounds and warfronts are the only instances with subzones
if inInstance and instanceType ~= "pvp" then return end
-- Get our subzone data
if subZone then
watchedFactionID = CitySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
end
elseif not watchedFactionID then
if (isWoDZone and bodyguardRepID) or inInstance then return end
-- Get world zone data or the character's default watched faction
watchedFactionID = zonesAndFactions[uiMapID] or db.defaultRepID
self:Print("DEBUG: watchedFactionID:", watchedFactionID)
end
-- WoW has a delay whenever the player changes instance/zone/subzone/tabard; factionName and isWatched aren't available immediately, so delay the lookup, then set the watched faction on the bar
C_Timer.After(db.delayGetFactionInfoByID, function()
if type(watchedFactionID) == "number" then
-- We have a factionID for the instance/zone/subzone/tabard or we don't have a factionID and db.defaultRepID is a number
factionName, _, _, _, _, _, _, _, _, _, _, isWatched = GetFactionInfoByID(watchedFactionID)
if factionName and not isWatched then
C_Reputation.SetWatchedFaction(watchedFactionID)
if db.verbose then
self:Print(L["Now watching %s"]:format(factionName))
end
end
else
-- watchedFactionID is not valid because there is no factionID for the instance/zone/subzone/tabard or db.defaultRepID is not a number
C_Reputation.SetWatchedFaction(0)
end
end)
end