#What does "or" do when defining variables

1 messages · Page 1 of 1 (latest)

void mantle
#

I am familiar with luau and other languages and how the term "or" is used. What I am confused about is its use with variables.

For example what would "local character = player.Character or (some other term)" declare the variable as? My first guess is that the variable is set to whichever value exists but i don't know how that would work if both values exist.

Anyone familiar with how the "or" term works in this context, please let me know. Thanks

queen bluff
#

lua checks from left to right

#

so if player.Character is nil, it returns the next one

#

if it's also nil, then the next, etc.

void mantle
#

thank you, it seems so much more obvious thinking about it now

queen bluff
#
local Answer = 3
local Var = (1 + 1 == Answer) and "Yes, the answer is 2" or "Wrong"

print(Var) -- "Wrong"
#

if all statements are valid, it returns the furthest statement; aka "Yes, the answer is 2"

solar mirage
#

i think is more readable

queen bluff
#

^

ionic vigil
#

yes