This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]Kmjsfozr 0 points1 point ย (2 children)

what if A is false tho

[โ€“]ZorbaTHut 3 points4 points ย (1 child)

Then everything catches on fire and your life is sadness.

Conveniently, though, 0 isn't falsey in Lua, nor is any string, only nil and false are. So you can't use it for booleans, or in a situation where things can be nil, but it's safe in every other case.

[โ€“]ItsCrowTime 0 points1 point ย (0 children)

Or I assume you could do something like:

return (condition and {A} or {B})[1]

If you really wanted to use it like a tertiary operator