加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua – 如何在此代码中找到缺少的括号?

发布时间:2020-12-14 21:48:00 所属栏目:大数据 来源:网络整理
导读:当我运行代码时,它告诉我在’=’附近有一个’)’错误: function restartLvl() for i = 1,#balloonTexts do display.remove(balloonTexts[i]) print ("restart level") end score.text = '0' ballRemain.text = '3' balloonText = {} createBalloons(1,3) if
当我运行代码时,它告诉我在’=’附近有一个’)’错误:

function restartLvl()
    for i = 1,#balloonTexts do
        display.remove(balloonTexts[i])
        print ("restart level")
    end

    score.text = '0'
    ballRemain.text = '3'
    balloonText = {}
    createBalloons(1,3)

    if (askUser.isVisible = true) then  --this is the line where the error occured
        askUser.isVisible = false
    end

    if (yesBtn.isVisible = true) then
        yesBtn.isVisible = false
    end

    if (noBtn.isVisible = true) then
        noBtn.isVisible = false
    end
end

我不知道它是如何仍然缺少’)’,因为我关闭了所有括号.

解决方法

=是赋值运算符,==是测试相等的运算符.将其更改为:

if (askUser.isVisible == true) then
    askUser.isVisible = false
end

还有其他所有人.为简单起见,可以省略括号():

if askUser.isVisible == true then
    askUser.isVisible = false
end

如果值是布尔值,您也可以这样做,因为所有非nil或false的值都被视为true.

if askUser.isVisible then
    askUser.isVisible = false
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读