If statement Lua-我需要一个4条件if语句
我所要寻找的是一种创建Lua if语句的方法,例如,在激活前需要满足4个条件If statement Lua-我需要一个4条件if语句,if-statement,lua,If Statement,Lua,我所要寻找的是一种创建Lua if语句的方法,例如,在激活前需要满足4个条件 If (x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4) then Return true End 我现在从Lua开始,只是想知道这是否有效,或者是否有其他方法!(如果有人已经有了问题,请联系我)谢谢你可以这样写,除了If、return和end不能在Lua中大写,并且If语句中不需要括号(尽管这不是语法错误): 但
If (x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4) then
Return true
End
我现在从Lua开始,只是想知道这是否有效,或者是否有其他方法!(如果有人已经有了问题,请联系我)谢谢你可以这样写,除了
If
、return
和end
不能在Lua中大写,并且If
语句中不需要括号(尽管这不是语法错误):
但是,如果要返回布尔值,直接返回逻辑运算符的结果会更简洁,完全避免使用if
语句:
return x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4
是的,将条件与
和连接起来会起作用。如果您想知道某个东西是否有效,请自己尝试一下。因为你是Lua的新手,我建议你看看Lua书中的编程(在线免费提供),里面回答了一些非常基本的问题,Lua是区分大小写的If
与If
不同。
return x == condition1 and x == condition2 and x ~= condition3 and x ~= condition4