【问题标题】:Lua if statement errorLua if 语句错误
【发布时间】:2013-04-09 13:29:05
【问题描述】:

我有这个 if 语句,当我运行它时它会返回一个错误:“')' 预期”

if (a=1 and b=4 and c=width/2) or (a=2 and b=1 and c=width/2) then
...
end

我在这里做错了吗?还是lua有问题?

【问题讨论】:

  • 我认为你的= 需要是=== 设置一个值,而== 比较值。
  • 不是我对 Lua 了解很多。但它不应该是 == 而不是 =?
  • 如果以下内容帮助您解决了问题,您应该将其标记为答案。操作方法如下:meta.stackexchange.com/questions/5234/…

标签: if-statement lua


【解决方案1】:

尝试用以下代码替换您当前的代码:

if (a==1 and b==4 and c==width/2) or (a==2 and b==1 and c==width/2) then
...
end

= 表示赋值,而== 检查是否相等,看起来您想检查是否相等。

【讨论】:

  • 哦哈哈我忘了,我已经习惯了xcode,它告诉我如果我犯了那个错误:P
猜你喜欢
  • 2010-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 2017-04-28
  • 2011-09-22
相关资源
最近更新 更多