Help with if and 'and not'
I had this other thread in the addon help section but it evolved to be more of a LUA problem so I'm posting it in here
Hi, I'm having trouble understanding the logic within 'if not' and 'and' in the same statement. Does that mean 'if not' AND 'if and not' or 'if not' AND 'if true'? I need to understand that to merge these two codes: Lua Code:
Lua Code:
Putting unitaffectingcombat, incombatlockdown, and the likes together with 'self.x ~= x or self.y ~= y' seems to be a good implementation, but it isn't proper. The big chunk of if situations (the first code) must be together with 'not ismouselooking() and getmousefocus() == worldframe' because these in these two situations the mouse will be standing still and it's the same for all the situations in the first big chunk of code. How do I do that? I tried just pasting everything after worldframe with lots of 'or's, didn't work, then changed all of them to 'and', which didn't work and ultimately changed to 'and not', and also didn't work. What to do? |
Hi,
I'm not real sure what you mean. "if and not" is not valid code. not only applies to the immediately following expression, unless you use parentheses, in case that helps. |
Quote:
That doesn't help. |
Lua Code:
|
|
Quote:
You can test it in the Live demo too http://www.lua.org/cgi-bin/demo Basically what MunkDev already described Lua Code:
Lua Code:
Code:
x | ¬ x ∧ y |
Something standing out to me is the check for GameTooltipTextLeft1:GetText(). In most if not all situations, I'd think this would always be returning something that would evaluate to true. I wouldn't expect the tooltip to actually clear the text when it hides, just when it's called to show something else. You might want to check GameTooltip:IsShown() instead.
|
1. When in doubt; use parantesis:
Code:
IF a and b or c and not d... 2. You can always use nesting of IF's. Code:
IF a and b LUA uses the same approach as most other languages when dealing with AND/OR: short-circuiting inclusive logical disjunction on two expressions. In short this means that it will skip the evaluation of the second part of an AND/OR expression if the first one is true. You can learn more about that by reading here; This is for VB.net that uses the opposite approach for AND/OR but has additional keywords (ANDALSO, ORELSE) that works like AND/OR in other languages. OrElse: https://msdn.microsoft.com/en-us/library/ea1sssb2.aspx AndAlso: https://msdn.microsoft.com/en-us/library/cb8x3kfz.aspx |
Lua (NOT LUA) is case-sensitive, so your examples of "IF" and "ElseIF" are a bit misleading. Likewise, showing examples of completely unrelated boolean logic for a semantically different language is... baffling.
There should be no "when in doubt" in this scenario; indeed, "Learn the language rules" should be the message. |
All times are GMT -6. The time now is 09:17 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI