Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can find the missing bracket in this code?

Tags:

lua

coronasdk

When I run the code it tells me there's an error which is ')' 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

I don't know how it is still missing a ')', because I closed all the brackets.

like image 521
user3305142 Avatar asked Mar 11 '14 08:03

user3305142


People also ask

How do I find missing brackets in C++?

A simple trick to find unbalanced braces and parentheses in C and C++ files is to run GNU indent across them. Throw away the output and only look at the warnings and errors produced, they will show unbalanced braces and parentheses also in dead code.

What is a bracket in code?

Brackets, or braces, are a syntactic construct in many programming languages. They take the forms of "[]", "()", "{}" or "<>." They are typically used to denote programming language constructs such as blocks, function calls or array subscripts. Brackets are also known as braces.


1 Answers

= is the assignment operator, == is the operator to test equality. Change it to:

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

And all the others as well. The brackets () can be ommited for simplicity:

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

If the value is a boolean, you can also do this because all values that are not nil or false are treated as true.

if askUser.isVisible then
    askUser.isVisible = false
end
like image 180
Yu Hao Avatar answered Nov 15 '22 08:11

Yu Hao