Lua - 我需要一个四个条件的 if 语句

我需要的只是创建一个 Lua if 语句,需要在激活之前满足 4 个条件,例如

If (x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4) then
Return true
End

我现在开始接触 Lua,只想知道这是否有效,或者是否有其他方法!(如果有人已经遇到过他的问题/问题,并且有一个答案,请给我链接)谢谢

点赞
用户6879826
用户6879826

你可以像之前一样写,除了在 Lua 中 ifreturnend 不应该大写,而在 if 语句中不需要括号(虽然这不是一个语法错误):

if x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4 then
   return true
end

但是,如果想要返回一个布尔值,直接返回逻辑运算符的结果会更清晰,完全避免了 if 语句:

return x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4
2019-02-07 16:03:45