If I do something like if A and B or C, what would the code think? Would it be (A and B) or C or A and (B or C)?
Am I able to change what the computer thinks via parentheses?
If I do something like if A and B or C, what would the code think? Would it be (A and B) or C or A and (B or C)?
Am I able to change what the computer thinks via parentheses?
Not really sure what you said, but are you wanting to look something like this?
local a = true
local b = false
local c = true
if a and (b or c) then
print("ye") -- will print, since a and c are true, b is not
end
I’m just wondering what happens.
You can just test this for yourself.
local A = true
local B = false
local C = true
if A and B or C then
print("True")
else
print("False")
end
But I don’t actually think you can test it that way. A and (B or C) would be true and true, because B or C is true or false so it returns true, therefore the output is true. But (A and B) or C would be false OR true, which still returns true, right? Am I missing something? Either way, I can’t check how to find this out right now, but I’ll think about it and respond later if I do.
local bool = a and b or c
Is treated as
local bool = (a and b) or c
If both a
and b
are truthy, c
won’t be used, if one of them is falsey, c
will be used.
Pretty sure you can change the order of operations through parenthesis, as that’s what it says on the Lua 5.1 documentation for the topic.
You might want to check out this post that has answered a similar question 2 years ago.
Make sure you check the forum for any duplicates beforehand next time.
i tried and nothing showed up (probably wrong search terms)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.