Lua:尝试将布尔值与数字进行比较 [英] Lua: attempt to compare boolean with number

查看:110
本文介绍了Lua:尝试将布尔值与数字进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个错误:试图将带有数字的布尔值与以下代码进行比较:

I came across an error: attempt to compare boolean with number with the following code:

local x = get_x_from_db() -- x maybe -2, -1 or integer like 12345
if 0 < x < 128 then
    -- do something
end

什么原因导致此错误?谢谢.

What causes this error? Thanks.

推荐答案

0<x <128 等效于(0< x)<128),因此出现错误消息.

0 < x < 128 is equivalent to (0 < x) < 128), hence the error message.

将测试写为 0<x和x <128 .

这篇关于Lua:尝试将布尔值与数字进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆