"Luau and C# Comparison" page uses outdated syntax for ternary operators

Issue Description

This is not a severe issue by any means as it is not misleading, especially given that Roblox Studio warns about this syntax.

The page states:

Luau doesn’t offer a direct equivalent to the C# conditional operator, a ? b : c. However, the Luau idiom a and b or c offers a close approximation, provided b isn’t false or nil. For a complete explanation of this idiom, see lua-users wiki. You may need to surround this idiom with parenthesis in some cases.

A proposed new explanation is:

C#'s ternary operator a ? b : c can be achieved in Luau using if a then b else c. Note that unlike traditional if statements, ternary operators in Luau are not closed with the end keyword. This serves as a superior alternative to the a and b or c idiom commonly used in traditional Lua because is not subject to the side effects of b being false or nil. Luau’s implementation also provides a way to chain statements together with elseif, for example: if a then b elseif c then d else e is identical to a ? b : (c ? d : e)

Issue Area: Documentation Content
Page URL: Luau and C# Comparison | Roblox Creator Documentation

4 Likes

Thanks for the report! We’ll follow up when we have an update for you.

1 Like

Hi there,
Apologies for the late reply; we’ve added documentation around this here:

Best regards,
IgnisRBX