I have been battling with logic for a long time in RepByZone. The idea is to switch the watched reputation based on the player's location, but only if certain things are true. To that end, I have tried many, many iterations of the logic. Sometimes I get it mostly working, but it never did work 100%.
The one thing that eluded me was if there was no zone data, in which case the code should fall back to some racial default. For whatever reason, I couldn't get it to work.
My latest attempt truly baffles me. Looking at Core-Retail.lua on lines 639–647, the debug print is telling me that watchedFactionID is a Boolean when it should be a number, assuming it is not nil. How it figures to be Boolean, I have no idea, which is why I am asking here.
The short section can be read below. I attached the full zip to show that numbers exist. The function starts on line 569. If I can solve why I am getting a Boolean rather than a number, I will adapt the code for Core-Vanilla.lua and Core-Wrath.lua, both of which are a little different (and working except for the fallback reputation). You can see them in the zip.
What am I not understanding about Lua? Too many "and" per line? Does Lua not treat "true and number" as a number?
Lua Code:
watchedFactionID = watchedFactionID == nil and inInstance and hasDungeonTabard and tabardID
watchedFactionID = watchedFactionID == nil and lookUpSubZones and citySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
watchedFactionID = watchedFactionID == nil and inInstance and instancesAndFactions[whichInstanceID]
watchedFactionID = watchedFactionID == nil and not lookUpSubZones and isWoDZone and bodyguardRepID
watchedFactionID = watchedFactionID == nil and not inInstance and zonesAndFactions[uiMapID] or watchedFactionID = watchedFactionID == nil and self.fallbackRepID
-- debug print
self:Print("watchedFactionID is", watchedFactionID or type(watchedFactionID))