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

use*_*142 5 lua coronasdk

当我运行代码时,它告诉我有一个错误')' expected near '=':

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
Run Code Online (Sandbox Code Playgroud)

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

Yu *_*Hao 7

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

if (askUser.isVisible == true) then
    askUser.isVisible = false
end
Run Code Online (Sandbox Code Playgroud)

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

if askUser.isVisible == true then
    askUser.isVisible = false
end
Run Code Online (Sandbox Code Playgroud)

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

if askUser.isVisible then
    askUser.isVisible = false
end
Run Code Online (Sandbox Code Playgroud)