Hey, and thanks for reading in advance. Stupid question warning!
I learned by reading a few scripts made by my friends that you can enumerate a true/false statement to a number without needing an if/then block.
local bool = false
local number = 7
number = number + ((bool and 3) or 0)
-- is the same as --
if bool then
number += 3
end
How exactly does that evaluate to a number? Are there any other weird syntax shortcuts like this?
Sorry, not exactly a high-priority thread, just curious.
that is what you’d call an addition assign operator. The addition assignment operator ( += ) adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible.
yes i was explaining the addition assignment operator as that was being used in the second comparison, but yes the ternary operator is also being used.