Thread Tools Display Modes
09-24-23, 03:03 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Code isn't functioning in WoD zones

RepByZone's code should either set the watched faction to the combat ally/bodyguard or Stormwind/Orgrimmar if the player has no bodyguard.

With testing, I know that the variable bodyguardRepID contains data for the character with a bodyguard, and nil for characters without a bodyguard. However, the print statement on line 627 of Core-Retail.lua isn't doing anything when I am in my garrison or any WoD zone. Nothing gets printed. The entire line doesn't fire, and I don't know why.

It fires for every other location I've tested, just not any WoD zones.

Attached is the full zip, which contains non-retail files. Those are working, although I'll be streamlining them later. But the non-retail files aren't the issue.

I'd appreciate any bright ideas or insight into why WoD zones are different and what is (not) going on when I go to them.

Thank you.

EDIT: not only is line 627 not firing in WoD zones, the variable watchedFactionID is not a number, so the watched rep bar gets cleared, regardless of whether having a bodyguard or not. The watched faction isn't even Stormwind or Orgrimmar.
Attached Files
File Type: zip RepByZone.zip (237.7 KB, 49 views)

Last edited by myrroddin : 09-24-23 at 03:15 PM. Reason: More debug testing information
  Reply With Quote
09-25-23, 12:09 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
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:
  1. -- Player switched zones, subzones, or instances, set watched faction
  2. function RepByZone:SwitchedZones(event)
  3.     if not db.enabled then return end -- Exit if the addon is disabled
  4.  
  5.     -- Possible zoning issues, exit out unless we have valid map data
  6.     local uiMapID = C_Map.GetBestMapForUnit("player")
  7.     if not uiMapID then return end
  8.  
  9.     if isOnTaxi then
  10.         if not db.watchOnTaxi then
  11.             -- On taxi but don't switch
  12.             return
  13.         end
  14.     end
  15.  
  16.     -- Some data may not be available because of the specialty zone functions, get something until a full data update refreshes things
  17.     instancesAndFactions = instancesAndFactions or self:InstancesAndFactionList()
  18.     zonesAndFactions = zonesAndFactions or self:ZoneAndFactionList()
  19.     subZonesAndFactions = subZonesAndFactions or self:SubZonesAndFactionsList()
  20.  
  21.     if event == "BODYGUARD_UPDATED" then
  22.         -- This is a custom event
  23.         bodyguardRepID = self:GetActiveBodyguardRepID()
  24.     else
  25.         -- bodyguardRepID might still be nil if there is no bodyguard
  26.         bodyguardRepID = bodyguardRepID or self:GetActiveBodyguardRepID()
  27.     end
  28.  
  29.     -- Set up variables
  30.     local _, watchedFactionID, factionName, isWatched
  31.     local hasDungeonTabard = false
  32.     local inInstance, instanceType = IsInInstance()
  33.     local whichInstanceID = inInstance and select(8, GetInstanceInfo())
  34.     local parentMapID = C_Map.GetMapInfo(uiMapID).parentMapID
  35.     local subZone = GetMinimapZoneText()
  36.     local isWoDZone = self.WoDFollowerZones[uiMapID] or (self.WoDFollowerZones[uiMapID] == nil and self.WoDFollowerZones[parentMapID])
  37.  
  38.     -- Apply instance reputations. Garrisons return false for inInstance and "party" for instanceType, which is good, we can filter them out
  39.     if inInstance and instanceType == "party" then
  40.         hasDungeonTabard = false
  41.         -- Certain dungeons do not benefit from tabards
  42.         if self.tabardExemptDungeons[whichInstanceID] then
  43.             return
  44.         end
  45.         -- Process faction tabards
  46.         if db.useFactionTabards then
  47.             if tabardID then
  48.                 watchedFactionID = tabardID
  49.                 hasDungeonTabard = true
  50.             end
  51.         else
  52.             -- We aren't watching faction tabards
  53.             hasDungeonTabard = false
  54.         end
  55.     else
  56.         -- We aren't in a party
  57.         hasDungeonTabard = false
  58.     end
  59.  
  60.     -- We aren't in an instance that supports tabards or we aren't watching tabards in the dungeon
  61.     if inInstance and not hasDungeonTabard then
  62.         watchedFactionID = instancesAndFactions[whichInstanceID]
  63.     end
  64.  
  65.     -- Override in WoD zones only if a bodyguard exists
  66.     if isWoDZone and bodyguardRepID then
  67.         watchedFactionID = bodyguardRepID
  68.     end
  69.  
  70.     -- Process subzones
  71.     if db.watchSubZones then
  72.         -- Don't loop through subzones if the player is watching a bodyguard rep
  73.         if isWoDZone and bodyguardRepID then return end
  74.  
  75.         -- Battlegrounds and warfronts are the only instances with subzones
  76.         if inInstance and instanceType ~= "pvp" then return end
  77.  
  78.         -- Get our subzone data
  79.         if subZone then
  80.             watchedFactionID = CitySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
  81.         end
  82.     elseif not watchedFactionID then
  83.         if (isWoDZone and bodyguardRepID) or inInstance then return end
  84.         -- Get world zone data or the character's default watched faction
  85.         watchedFactionID = zonesAndFactions[uiMapID] or db.defaultRepID
  86.  
  87.         self:Print("DEBUG: watchedFactionID:", watchedFactionID)
  88.     end
  89.  
  90.     -- 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
  91.     C_Timer.After(db.delayGetFactionInfoByID, function()
  92.         if type(watchedFactionID) == "number" then
  93.             -- We have a factionID for the instance/zone/subzone/tabard or we don't have a factionID and db.defaultRepID is a number
  94.             factionName, _, _, _, _, _, _, _, _, _, _, isWatched = GetFactionInfoByID(watchedFactionID)
  95.             if factionName and not isWatched then
  96.                 C_Reputation.SetWatchedFaction(watchedFactionID)
  97.                 if db.verbose then
  98.                     self:Print(L["Now watching %s"]:format(factionName))
  99.                 end
  100.             end
  101.         else
  102.             -- watchedFactionID is not valid because there is no factionID for the instance/zone/subzone/tabard or db.defaultRepID is not a number
  103.             C_Reputation.SetWatchedFaction(0)
  104.         end
  105.     end)
  106. end
  Reply With Quote
09-25-23, 02:01 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
More debugging. watchedFactionID is nil with the following code, at least for WoD zones and now subzones too, as "Dwarven District" in Stormwind stopped working. It is supposed to be 47 for Ironforge. It is 72 when I'm in other parts of Stormwind and 2510 in Valdrakken, so the major zones are working.

I also tested the addon settings and disabled Lunarfall (the Alliance Garrison) checking for a bodyguard, and suddenly the bar went from blank to Stormwind. This tells me something about isWoDZone and/or bodyguardRepID, and that I'm not handling one or both correctly. I'm not seeing the logic bomb.

As fast as I am getting answers, I am getting more confused about WoD and subzones. Besides anyone being helpful with debugging, I would love to learn why it isn't working, not just a fix.
Lua Code:
  1. -- Process subzones
  2. if db.watchSubZones then
  3.     -- Battlegrounds and warfronts are the only instances with subzones
  4.     if inInstance and instanceType ~= "pvp" then return end
  5.  
  6.     -- Don't loop through subzones if the player is watching a bodyguard rep
  7.     if isWoDZone and bodyguardRepID then
  8.         watchedFactionID = bodyguardRepID
  9.     else
  10.         -- Get our subzone data
  11.         watchedFactionID = CitySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
  12.     end
  13. end
  14.  
  15. -- Get world zone data or the character's default watched faction
  16. watchedFactionID = (watchedFactionID == nil and zonesAndFactions[uiMapID]) or db.defaultRepID
  17.  
  18. self:Print("DEBUG: watchedFactionID:", watchedFactionID)
  Reply With Quote
09-25-23, 02:53 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I solved it, yet even though I solved the issues, I can't explain why this was necessary or what my prior method was doing wrong.
Lua Code:
  1. -- Process subzones
  2. if db.watchSubZones then
  3.     -- Battlegrounds and warfronts are the only instances with subzones
  4.     if inInstance and instanceType ~= "pvp" then return end
  5.  
  6.     -- Don't loop through subzones if the player is watching a bodyguard rep
  7.     if isWoDZone and bodyguardRepID then
  8.         watchedFactionID = bodyguardRepID
  9.     else
  10.         -- Get our subzone data
  11.         watchedFactionID = CitySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
  12.     end
  13. end
  14.  
  15. -- Get world zone data or the character's default watched faction. For some unknown reason, watchedFactionID loses data from bodyguards and instances at this stage in the code, refresh
  16. if watchedFactionID == nil then
  17.     if isWoDZone and bodyguardRepID then
  18.         watchedFactionID = bodyguardRepID
  19.     elseif inInstance and hasDungeonTabard then
  20.         watchedFactionID = tabardID
  21.     elseif inInstance then
  22.         watchedFactionID = instancesAndFactions[whichInstanceID] or db.defaultRepID
  23.     else
  24.         watchedFactionID = zonesAndFactions[uiMapID] or db.defaultRepID
  25.     end
  26. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Code isn't functioning in WoD zones


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off