gpt4 book ai didi

lua - 如何在这段代码中找到丢失的括号?

转载 作者:行者123 更新时间:2023-12-04 18:07:53 24 4
gpt4 key购买 nike

当我运行代码时,它告诉我有一个错误 ')' 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

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

最佳答案

=是赋值运算符,==是检验相等性的运算符。将其更改为:

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

以及所有其他人。括号 ()为简单起见可以省略:
if askUser.isVisible == true then
askUser.isVisible = false
end

如果值是 bool 值,您也可以这样做,因为所有不是 nil 的值或 false被视为真实。
if askUser.isVisible then
askUser.isVisible = false
end

关于lua - 如何在这段代码中找到丢失的括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22319778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com