I do not understand why I am getting type Boolean when I should be getting number
1 Attachment(s)
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:
|
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. |
Code:
watchedFactionID = watchedFactionID == nil and inInstance and hasDungeonTabard and tabardID Code:
if watchedFactionID == nil and inInstance == AnythingButNilOrFalse and hasDungeonTabard == AnythingButNilOrFalse and tabardID == AnythingButNilOrFalse then 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 |
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 is how I would implement a fallback list using multiple ors.
Lua Code:
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. |
Quote:
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. |
Quote:
Thank you so much! |
All times are GMT -6. The time now is 08:01 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI