I don’t know why someone did that. a and b evaluates to a if a is falsey, b otherwise. var would get 2 and somePart.Position gets Vector3.new(255, 255, 255).
The difference is it creates a new scope. You can declare locals in that do ... end and they won’t be accessible to the outer scope.
local a = false or 1 -- if first value is false/nil, the second value is valid(1)
local b = false and 1 -- if first value is false/nil, the first value is valid(false)
have u got a working example of any code that actually uses
and when setting a variable because i havent seen it before
people might use:
local pie, chicken, turkey = game.workspace.pie, game.workspace.chicken, game.workspace.turkey
not
local pie, chicken, turkey = game.workspace.pie and game.workspace.chicken and game.workspace.turkey
in other higher level languages like python you would use a simillar thing to do you would use a colon however in lua the “do” / “:” is automatically added in, in a sense
it would theoretically go after an else statement or an if statment but you only put them after a loop is declared in lua so no the “do”'s are autmatically added in (invisibly is a way to think about it) now im not 100% sure on this but thats all there really is to know about it
-- result = *statement* and *if it's true* or *if it's false*
local statementIsTrue = true and 'Is true' or 'Is false'
print(statementIsTrue) -- "Is true"
local statementIsTrue = false and 'Is true' or 'Is false'
print(statementIsTrue) -- "Is false"
You can use this instead of using if statements for simple stuff.
For example:
local a = 1
local b = 2
local higherNumber
if a > b then
higherNumber = a
else
higherNumber = b
end
That could be converted to:
local a = 1
local b = 2
local higherNumber = (a > b) and a or b