5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3305142
  • 227
  • 1
  • 2
  • 9

2 Answers2

7

= 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
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • Strike "If the value is a boolean". – Tom Blodget Mar 12 '14 at 02:28
  • It works as well if the value of NOT a boolean. However, it's not exactly equivalent to the condition in the question (tests explicitly if the value is `true`). – Yu Hao Mar 12 '14 at 04:37
  • Yes, you're right. The mentioning of `nil` threw me off because `nil` is not `boolean`. Your statement is nuanced but correct. – Tom Blodget Mar 12 '14 at 11:03
  • The stylistic pattern that the question asker uses "expression == true" and "expression == false" is a curious but not uncommon one. Perhaps it should be avoided in Lua. In general, the only time I see it making sense is where it improves readability but in most such cases, renaming a field, function or variable would be a better way. `if askUser.isVisible then` reads just fine to me. – Tom Blodget Mar 12 '14 at 11:04
0

This is not related to your answer but

I recommend you to use lua glider IDE because this type error can be detect well by using this IDE.