if cbBankerTwoCardValue == 4 and (cbPlayerThirdCardValue ~= 0 or cbPlayerThirdCardValue ~= 1 or cbPlayerThirdCardValue ~= 8 or cbPlayerThirdCardValue ~= 9) then print("111") cbBankerThirdCardValue = 1 end 为什么cbBankerTwoCardValue == 4 cbPlayerThirdCardValue = 1 会进来吗
时间: 2023-08-15 11:06:48 浏览: 23
这段代码中的条件判断存在逻辑错误,如果cbPlayerThirdCardValue == 1,那么它一定不等于0,这时候cbPlayerThirdCardValue ~= 0会返回true,if语句块就会被执行。同样地,cbPlayerThirdCardValue ~= 1、cbPlayerThirdCardValue ~= 8、cbPlayerThirdCardValue ~= 9也会分别返回true,因此无论cbPlayerThirdCardValue取什么值,这个if语句块都会被执行。如果你想判断cbPlayerThirdCardValue是否等于0、1、8、9中的任何一个,应该使用逻辑运算符“and”而不是“or”,即:
```
if cbBankerTwoCardValue == 4 and (cbPlayerThirdCardValue ~= 0 and cbPlayerThirdCardValue ~= 1 and cbPlayerThirdCardValue ~= 8 and cbPlayerThirdCardValue ~= 9) then
print("111")
cbBankerThirdCardValue = 1
end
```
这样修改后,只有当cbBankerTwoCardValue为4且cbPlayerThirdCardValue不等于0、1、8、9中的任何一个时,才会执行if语句块。