'end' expected (to close 'function' at line 102) near <eof>

120 Views Asked by At

I am getting this error

'end' expected (to close 'function' at line 102) near



button:addEventListener("tap", function()

buttonText.isVisible=false
button.isVisible=false
sun.isVisible=false
myText.isVisible=false
myText=display.newText("Rock, Paper, Scissors",w*.5,h*.1,native.systemFont,30)
myText:setFillColor(unpack(limegreen))

options={"rock","paper","scissors"}
computerChoice=options[math.random(3)]

local rockButton = display.newRoundedRect(w*.5,h*.3,w*.5,h*.2,25)
rockButton.anchorX=.5
rockButton.anchorY=.5
rockButton:setFillColor(unpack(redorange))
local rockText=display.newText("Rock",w*.5,h*.3,systemFont,50)
rockText:setFillColor(unpack(blue))

local paperButton = display.newRoundedRect(w*.5,h*.6,w*.5,h*.2,25)
paperButton.anchorX=.5
paperButton.anchorY=.5
paperButton:setFillColor(unpack(redorange))
local paperText=display.newText("Paper",w*.5,h*.6,systemFont,50)
paperText:setFillColor(unpack(blue))

local scissorsButton = display.newRoundedRect(w*.5,h*.9,w*.5,h*.2,25)
scissorsButton.anchorX=.5
scissorsButton.anchorY=.5
scissorsButton:setFillColor(unpack(redorange))
local scissorsText=display.newText("Scissors",w*.5,h*.9,systemFont,50)
scissorsText:setFillColor(unpack(blue))

rockButton:addEventListener("tap",function()
rockButton.isVisible=false
rockText.isVisible=false
paperButton.isVisible=false
paperText.isVisible=false
scissorsButton.isVisible=false
scissorsText.isVisible=false
playerChoice="rock"
local computerChoiceText=display.newText("Computer's Choice: "..computerChoice,w*.5,h*.3,native.systemfont,25)

if computerChoice=="paper" then
   local whoWonText=display.newText("Player Choice: "..playerChoice.."You LOST!",w*.5,h*.5,native.systemFont,20)

elseif computerChoice=="scissors" then
   local whoWontText=display.newText("Player Choice: "..playerChoice.."You WON!",w*.5,h*.5,native.systemFont,20)

else
   local whoWontText=display.newText("Player Choice: "..playerChoice.."You TIE!",w*.5,h*.5,native.systemFont,20)
end

paperButton:addEventListener("tap",function()
rockButton.isVisible=false
rockText.isVisible=false
paperButton.isVisible=false
paperText.isVisible=false
scissorsButton.isVisible=false
scissorsText.isVisible=false
playerChoice="paper"
local computerChoiceText=display.newText("Computer's Choice: "..computerChoice,w*.5,h*.3,native.systemfont,25)

if computerChoice=="paper" then
   local whoWonText=display.newText("Player Choice: "..playerChoice.."You Tie!",w*.5,h*.5,native.systemFont,20)

elseif computerChoice=="scissors" then
   local whoWontText=display.newText("Player Choice: "..playerChoice.."You WON!",w*.5,h*.5,native.systemFont,20)

else
   local whoWontText=display.newText("Player Choice: "..playerChoice.."You TIE!",w*.5,h*.5,native.systemFont,20)
end

scissorsButton:addEventListener("tap",function()
rockButton.isVisible=false
rockText.isVisible=false
paperButton.isVisible=false
paperText.isVisible=false
scissorsButton.isVisible=false
scissorsText.isVisible=false
playerChoice="scissors"
local computerChoiceText=display.newText("Computer's Choice: "..computerChoice,w*.5,h*.3,native.systemfont,25)

if computerChoice=="paper" then
   local whoWonText=display.newText("Player Choice: "..playerChoice.."You WON!",w*.5,h*.5,native.systemFont,20)

elseif computerChoice=="scissors" then
   local whoWontText=display.newText("Player Choice: "..playerChoice.."You TIE!",w*.5,h*.5,native.systemFont,20)

else
   local whoWontText=display.newText("Player Choice: "..playerChoice.."You LOST!",w*.5,h*.5,native.systemFont,20)
end
end)

I have an end for each of the functions

I've gone through my code multiple times, and just cant find what's wrong, and I keep getting the same error, but occasionally on different lines if I try to fix it by adjusting parentheses. Someone suggested properly indenting it, but I'm still getting the error

1

There are 1 best solutions below

0
Todd Trann On

For each of your anonymous listener functions, they do not appear to be ended at all. For example, assuming that the first listener should be ended after the limegreen text, you would change this:

button:addEventListener("tap", function()

buttonText.isVisible=false
button.isVisible=false
sun.isVisible=false
myText.isVisible=false
myText=display.newText("Rock, Paper, Scissors",w*.5,h*.1,native.systemFont,30)
myText:setFillColor(unpack(limegreen))

options={"rock","paper","scissors"}

to this:

button:addEventListener("tap", 
    function()
        buttonText.isVisible=false
        button.isVisible=false
        sun.isVisible=false
        myText.isVisible=false
        myText=display.newText("Rock, Paper, Scissors",w*.5,h*.1,native.systemFont,30)
        myText:setFillColor(unpack(limegreen))
    end )

options={"rock","paper","scissors"}

The end closes off the anonymous function. The trailing ) closes off the start of addEventListener.