【问题标题】:if statement failing in luaif语句在lua中失败
【发布时间】:2013-02-28 10:16:33
【问题描述】:

我有以下测试lua代码:

   err = nextUsernumber
   res = false 
   if not res and err then
      print("error")
      errtxt = err
   end

但逻辑永远不会进入 if 语句。

我尝试在 if 子句周围加上括号(),如下所示:

if (not res) and (err) then

你能告诉我我错过了什么吗?

谢谢。

【问题讨论】:

    标签: if-statement lua


    【解决方案1】:

    我是if ... then(见manual):

    if not res and err then
      print("error")
      errtxt = err
    end
    

    另外,请确保err 既不是nil 也不是false,因为在控制语句中两者都被认为是错误的(参见上面的手册部分)。

    【讨论】:

      【解决方案2】:

      您缺少then 子句。 Lua 需要 then 声明 if。

      if not res and err then
          print("error")
          errtxt = err
      end
      

      【讨论】:

      • 你好。我显然没有正确剪切和粘贴。我的代码中确实有一个“then”。
      猜你喜欢
      • 2018-02-02
      • 2019-01-26
      • 2018-11-06
      • 2021-10-17
      • 2015-02-24
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 2021-07-19
      相关资源
      最近更新 更多