Lua- 测试两个值是否为真
Lua- Test if two values are true
我正在尝试测试一个或两个值是否为真。我的代码在 '!' 之后一直期待 "then"。
if x != 0 or y != 0 then
player:doStuff(x, y)
end
根据 Lua doco:
3.4.4 – Relational Operators
Lua supports the following relational operators:
== : equality
~= : inequality
< : less than
> : greater than
<= : less or equal
>= : greater or equal
以下抄本显示了错误和正确的方式:
$ lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
>
> if 1 != 0 then
stdin:1: 'then' expected near '!'
>
> if 1 ~= 0 then
>> print "unequal"
>> end
unequal
>
我正在尝试测试一个或两个值是否为真。我的代码在 '!' 之后一直期待 "then"。
if x != 0 or y != 0 then
player:doStuff(x, y)
end
根据 Lua doco:
3.4.4 – Relational Operators
Lua supports the following relational operators:
== : equality
~= : inequality
< : less than
> : greater than
<= : less or equal
>= : greater or equal
以下抄本显示了错误和正确的方式:
$ lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
>
> if 1 != 0 then
stdin:1: 'then' expected near '!'
>
> if 1 ~= 0 then
>> print "unequal"
>> end
unequal
>