Thread Tools Display Modes
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, 20 views)
  Reply With Quote
03-23-24, 07:11 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
I can't see anything clearly wrong with your code.

nUI auto switches rep fine ( although admittedly I haven't played properly much recently so a recent patch may have done something, but no one has reported anything yet in that regards ) .

I would suggest checking each lines values and see if any of them result in a true or false value for the watchedFactionID variable. Which would mean the following lines would not execute.

Is that last line supposed to have that extra test at the end ? It seems like it should be on the next line rather than as an or statement. Technically shouldn't make a difference but hard to say.

Edit:
Also, you might find you need to put some of those tests in brackets to ensure the right results are being tested and the right value being assigned. That's messed me up a few times when I've done assignment lines like that.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 03-23-24 at 07:20 AM.
  Reply With Quote
03-23-24, 09:53 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Code:
watchedFactionID = watchedFactionID == nil and inInstance and hasDungeonTabard and tabardID
That resoves to a boolean
Code:
if watchedFactionID == nil and inInstance == AnythingButNilOrFalse and hasDungeonTabard == AnythingButNilOrFalse and tabardID == AnythingButNilOrFalse then
   watchedFactionID = true
else
   watchedFactionID = false
end
which means watchedFactionID won't be nil for the others because it will always be true or false (boolean).


Maybe:
Code:
watchedFactionID = (watchedFactionID == nil and inInstance and hasDungeonTabard) and tabardID or nil
Code:
if watchedFactionID = (watchedFactionID == nil and inInstance == AnythingButNilOrFalse and hasDungeonTabard == AnythingButNilOrFalse) then 
    watchedFactionID = tabardID
else
    watchedFactionID = nil
end
(Define your truth) and (then make an assigment if true) or (other assigment [defaults to false if no "or" and truth is not met])
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-23-24 at 12:30 PM.
  Reply With Quote
03-23-24, 05:17 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Every check for watchedFactionID==nil is overwriting watchedFactionID with false whenever it isn't nil.

-also-

Code:
watchedFactionID = watchedFactionID == nil and not inInstance and zonesAndFactions[uiMapID] or watchedFactionID = watchedFactionID == nil and self.fallbackRepID
This should be throwing a syntax error since you can't have an assignment operator (=) in the middle of an expression.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 03-23-24 at 05:25 PM.
  Reply With Quote
03-23-24, 08:44 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
This is how I would implement a fallback list using multiple ors.
Lua Code:
  1. watchedFactionID = watchedFactionID
  2.     or (inInstance and hasDungeonTabard and tabardID)
  3.     or (lookUpSubZones and (citySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]))
  4.     or (inInstance and instancesAndFactions[whichInstanceID])
  5.     or (not lookUpSubZones and isWoDZone and bodyguardRepID)
  6.     or (not inInstance and zonesAndFactions[uiMapID])
  7.     or self.fallbackRepID

Note parenthesis are highly suggested to direct which order you want logic operations to run as mixing and/or operations can lead to unpredictable results.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-24-24, 03:18 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Xrystal View Post

Is that last line supposed to have that extra test at the end ? It seems like it should be on the next line rather than as an or statement. Technically shouldn't make a difference but hard to say.
That is a typo. It shouldn't look like that, no. Somehow I copied and pasted from my snippet back into the main file and saved it before I created a zip.

I will check the other answers and do some testing. I saw the SDPhantom's answer that explains it is overwriting nil with false. I realized that a few minutes before I booted my computer to check the forums. Yep, my brain is an entire day behind.
  Reply With Quote
03-24-24, 04:13 AM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by SDPhantom View Post
This is how I would implement a fallback list using multiple ors.
Lua Code:
  1. watchedFactionID = watchedFactionID
  2.     or (inInstance and hasDungeonTabard and tabardID)
  3.     or (lookUpSubZones and (citySubZonesAndFactions[subZone] or subZonesAndFactions[subZone]))
  4.     or (inInstance and instancesAndFactions[whichInstanceID])
  5.     or (not lookUpSubZones and isWoDZone and bodyguardRepID)
  6.     or (not inInstance and zonesAndFactions[uiMapID])
  7.     or self.fallbackRepID

Note parenthesis are highly suggested to direct which order you want logic operations to run as mixing and/or operations can lead to unpredictable results.
This solution worked! I tested in Un'Goro Crater, which has no rep assigned and the addon watched my fallback. Then I went into the Stockades dungeon with the Ironforge faction tabard, which worked. And finally, I flew back and forth between the main section of Valdrakken and the Artisan's section and that worked.

Thank you so much!
  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