Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement Lua-我需要一个4条件if语句_If Statement_Lua - Fatal编程技术网

If statement Lua-我需要一个4条件if语句

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语句中不需要括号(尽管这不是语法错误): 但

我所要寻找的是一种创建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
语句:

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