And, or, How do I use it in parameters?

image
How would I go about using “and” and “or” inside parameters like this?
When does “or” change the value?
Why is there an “and”? Is this because there are two parameters?

To explain (not sure if I can explain well), directory is the condition for it to lead to “/”…directory. If directory is nil or false, it will lead to “” example:

local words = 2

local str = "word" ..(words > 1 and "s" or "")

in this case, it will be “words”, but if the variable words is 1 or less, it will be “word”.

1 Like

It’s known as Lua short-circuit or short-cut evaluations, or just a short-cut for if statements

1 Like

Thank you two so much! I had to give a solution to someone, so sorry.
But you two explained it very well. Thanks :slight_smile:

1 Like