Thread Tools Display Modes
Prev Previous Post   Next Post Next
03-23-24, 04:54 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I do not understand why I am getting type Boolean when I should be getting number

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:
  1. watchedFactionID = watchedFactionID == nil and inInstance and hasDungeonTabard and tabardID
  2. watchedFactionID = watchedFactionID == nil and lookUpSubZones and citySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]
  3. watchedFactionID = watchedFactionID == nil and inInstance and instancesAndFactions[whichInstanceID]
  4. watchedFactionID = watchedFactionID == nil and not lookUpSubZones and isWoDZone and bodyguardRepID
  5. watchedFactionID = watchedFactionID == nil and not inInstance and zonesAndFactions[uiMapID] or watchedFactionID = watchedFactionID == nil and self.fallbackRepID
  6.  
  7. -- debug print
  8. self:Print("watchedFactionID is", watchedFactionID or type(watchedFactionID))
Attached Files
File Type: zip repbyzone.zip (1.52 MB, 36 views)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » I do not understand why I am getting type Boolean when I should be getting number


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