Button problem when entering scene in Storyboard

(I couldn’t find where to post this in the storyboard forum, it wasnt showing up in the forums section)

I am getting an error message when trying to enter the main menu after the loading scene. The error message states “error loading module ‘mainmenu’ from file, lua:50: ‘}’ expected (to cl”

Here is the code for one of my buttons

[lua]storyBtn = ui.newButton{
default.Src = “storybtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “storybtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “StoryButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
} [lua] [import]uid: 69494 topic_id: 30099 reply_id: 330099[/import]

Are you sure it’s the button and not something else. Storyboard can be tricky sometimes. What was the error message you cut it off? [import]uid: 75779 topic_id: 30099 reply_id: 120487[/import]

Lol that was the error message. My button function looks fine, I don’t understand why it says I need to close the brackets at line 1 (according to the numbers in this forum).

The actual error message probably meant it expected to close the brackets in line 1. As you can see, I closed it in line 15. The button code looks the same in my main game and I had no problem opening it. [import]uid: 69494 topic_id: 30099 reply_id: 120490[/import]

Can someone please help me? The storyboard is the last of my project and I would like to finish this sometime this week so I can test it out on my phone. [import]uid: 69494 topic_id: 30099 reply_id: 120686[/import]

use widget library instead of ui library to see if ui is causing the problems. I’ve already written the code for you to copy/paste. I had strange problems with ui.lua and switched to widget and all the errors went away. I’ve already published 2 games :smiley:

[code]
local widget = require “widget”

local storyBtn

local onPlayTouch = function(event)
– btn function
end

function scene:createScene( event )

local screenGroup = self.view
storyBtn = widget.newButton{
default = “storybtn.png”,
width = 100,
height = 100,
over = “storybtn-over.png”,
onEvent = onPlayTouch,
id = “StoryButton”,
label = “”,
font = “Helvetica”,
labelColor = { default={ 255, 255, 255, 255 }, over={ 255, 255, 255, 255 } },
size = 16,
}
screenGroup:insert(storyBtn)

end
[/code] [import]uid: 98393 topic_id: 30099 reply_id: 120852[/import]

I’m still getting the same error message. This time: "lua:50: ‘}’ expected (to close ‘{’ at line 49) near ‘=’

Maybe I’ll just post the whole code of the main menu:

[lua] --Require the “Widget” library (were using the slider)
local widget = require(“widget”)
–Require the physics library
local physics = require(“physics”)
–Require the UI Library
local ui = require(“ui”)

–Hide the device’s status bar
display.setStatusBar(display.HiddenStatusBar)

local displayGroup = display.newGroup()

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

local btnAnim
local btnSound = audio.loadSound(“btnSound.wav”)
function scene:createScene(event)
local displayGroup = self.view

storyboard.removeScene(“loadmainmenu”)
storyboard.removeScene(“levelselector”)
storyboard.removeScene(“arcade”)
storyboard.removeScene(“options”)

print( “\nmainmenu: createScene event” )

end

function scene:enterScene(event)
local displayGroup = self.view
print(“mainmenu: enterScene event”)

local backgroundImage = display.newImageRect(“mainmenu.png”, 480, 320)
backgroundImage.x = 240; backgroundImage.y = 160
displayGroup:insert(backgroundImage)

local storyBtn

local onPlayTouch = function(event)
if event.phase == “release” then
storyboard.gotoScene(“levelselector”, “fade”, 300)
end
end

storyBtn = widget.newButton{
default.Src = “storybtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “storybtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “StoryButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16
}

storyBtn.x = 240; storyBtn.y = 440
displayGroup:insert(storyBtn)

btnAnim = transition.to(storyBtn, {time=500, y=260, transition=easing.inOutExpo})

local optBtn
local onOptionsTouch = function(event)
if event.phase == “release” then

audio.play(btnSound)
storyboard.gotoScene(“options”, “crossfade”, 300)
end
end

local optBtn

optBtn = widget.newButton{
defaultSrc = “optbtn.png”,
defaultX = 60,
defaultY = 60,
overSrc = “optbtn-over.png”,
overX = 60,
overY = 60,
onEvent = onOptionsTouch,
id = “OptionsButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
}

optBtn.x = 430; optBtn.y = 440
displayGroup:insert(optBtn)

btnAnim = transition.to(optBtn, {time=500, y=280, transition=easing.inOutExpo})

local arcadeBtn

local arcadeBtn
local onOptionsTouch = function(event)
if event.phase == “release” then

audio.play(btnSound)
storyboard.gotoScene(“arcade”, “crossfade”, 300)
end
end

arcadeBtn = widget.newButton{
default.Src = “arcadebtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “arcadebtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “ArcadeButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
}

arcadeBtn.x = 240; arcadeBtn.y = 440
displayGroup:insert(arcadeBtn)

btnAnim = transition.to(arcadeBtn, {time=500, y=260, transition=easing.inOutExpo})

local brutalBtn

local brutalBtn
local onOptionsTouch = function(event)
if event.phase == “release” then

audio.play(btnSound)
storyboard.gotoScene(“brutal”, “crossfade”, 300)
end
end

brutalBtn = widget.newButton{
default.Src = “brutalBtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “brutalBtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “BrutalButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
}

brutalBtn.x = 240; brutalBtn.y = 440
displayGroup:insert(brutalBtn)

btnAnim = transition.to(brutalBtn, {time=500, y=260, transition=easing.inOutExpo})

end

function scene:exitScene()
if btnAnim then transition.cancel(btnAnim); end
print(“mainmenu: exitScene event”)
end

function scene:destroyScene(event)
print("((destorying mainmenu’s view))")
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene

[lua]I can’t see what I’m doing wrong here :confused: [import]uid: 69494 topic_id: 30099 reply_id: 120886[/import]

If you need to do something with the widget’s display object (such as place the button into a display group), you need to do so using the object’s .view property. Example:[/lua]
local myButton = widget.newButton{ label=“My Button” }

– WRONG, will produce error:
myGroup:insert( myButton )

– CORRECT: access display group with .view property
myGroup:insert( myButton.view )
[import]uid: 75779 topic_id: 30099 reply_id: 120890[/import]

Hi rmckee282002, you’re wrong on this one! I know,the API is a bit confusing, but you’ll find the change on the widget button api

[NOTE: Deprecated as of build 2012.721—the widget is now the display object]

If you need to do something with the widget’s display object (such as place the button into a display group), you need to do so using the object’s .view property

http://developer.coronalabs.com/reference/index/widgetnewbutton [import]uid: 98393 topic_id: 30099 reply_id: 120893[/import]

neilw711

I don’t know. A closing bracket could be missing on any line, so you should skim the whole file instead of just concentrating on the line when the Interpreter gets an error.
And yeah, comment out the “require ui.lua” I know sounds weird but I got errors with the latest ui.lua. [import]uid: 98393 topic_id: 30099 reply_id: 120895[/import]

I went through the whole file and everything seems fine to me. No matter what I edit, I get the same error message to close out the bracket. [import]uid: 69494 topic_id: 30099 reply_id: 120898[/import]

there are several things wrong with how you declare functions. I’ve rewritten the file and it works!

change your create function to this

function scene:enterScene(event)  
  
 local displayGroup = self.view  
 print("mainmenu: enterScene event")  
  
 local backgroundImage = display.newImageRect("mainmenu.png", 480, 320)  
 backgroundImage.x = 240; backgroundImage.y = 160  
 displayGroup:insert(backgroundImage)  
  
 local storyBtn  
  
 local onPlayTouch = function(event)  
 if event.phase == "release" then  
 storyboard.gotoScene("levelselector", "fade", 300)  
 end  
 end   
  
  
 storyBtn = widget.newButton{  
 default.Src = "storybtn.png",  
 defaultX = 100,  
 defaultY = 100,  
 overSrc = "storybtn-over.png",  
 overX = 100,  
 overY = 100,  
 onEvent = onPlayTouch,  
 id = "StoryButton",  
 text = "",  
 font = "Helvetica",  
 textColor = {255, 255, 255, 255},  
 size = 16  
 }  
  
  
 storyBtn.x = 240; storyBtn.y = 440  
 displayGroup:insert(storyBtn)  
  
 btnAnim = transition.to(storyBtn, {time=500, y=260, transition=easing.inOutExpo})  
  
  
 local onOptionsTouch = function(event)  
 if event.phase == "release" then  
  
 -- audio.play(btnSound)  
 storyboard.gotoScene("options", "crossfade", 300)  
 end  
 end  
  
  
 local optBtn  
  
 optBtn = widget.newButton{  
 defaultSrc = "optbtn.png",  
 defaultX = 60,  
 defaultY = 60,  
 overSrc = "optbtn-over.png",  
 overX = 60,  
 overY = 60,  
 onEvent = onOptionsTouch,  
 id = "OptionsButton",  
 text = "",  
 font = "Helvetica",  
 textColor = {255, 255, 255, 255},  
 size = 16,  
 emboss = false  
 }  
  
 optBtn.x = 430; optBtn.y = 440  
 displayGroup:insert(optBtn)  
  
 btnAnim = transition.to(optBtn, {time=500, y=280, transition=easing.inOutExpo})  
  
 local arcadeBtn  
  
  
 local onOptionsTouch = function(event)  
 if event.phase == "release" then  
  
-- audio.play(btnSound)  
 storyboard.gotoScene("arcade", "crossfade", 300)  
 end  
 end  
  
  
 arcadeBtn = widget.newButton{  
 default.Src = "arcadebtn.png",  
 defaultX = 100,  
 defaultY = 100,  
 overSrc = "arcadebtn-over.png",  
 overX = 100,  
 overY = 100,  
 onEvent = onPlayTouch,  
 id = "ArcadeButton",  
 text = "",  
 font = "Helvetica",  
 textColor = {255, 255, 255, 255},  
 size = 16,  
 emboss = false  
 }  
  
  
 arcadeBtn.x = 240; arcadeBtn.y = 440  
 displayGroup:insert(arcadeBtn)  
  
 btnAnim = transition.to(arcadeBtn, {time=500, y=260, transition=easing.inOutExpo})  
  
 local brutalBtn  
  
  
  
 brutalBtn = widget.newButton{  
 default.Src = "brutalBtn.png",  
 defaultX = 100,  
 defaultY = 100,  
 overSrc = "brutalBtn-over.png",  
 overX = 100,  
 overY = 100,  
 onEvent = onPlayTouch,  
 id = "BrutalButton",  
 text = "",  
 font = "Helvetica",  
 textColor = {255, 255, 255, 255},  
 size = 16,  
 emboss = false   
 }  
  
 brutalBtn.x = 240; brutalBtn.y = 440  
 displayGroup:insert(brutalBtn)  
  
 btnAnim = transition.to(brutalBtn, {time=500, y=260, transition=easing.inOutExpo})  
  
  
end  

I don’t know what you’ve tried to accomplish with this

 local storyBtn  
  
 local onPlayTouch = function(event)  
 if event.phase == "release" then  
 storyboard.gotoScene("levelselector", "fade", 300)  
 end  
 end   

you declared a local variable storyBtn, but you put an “end” to it like it is a function.
It’ll only work if you’d it written like
[lua] local function storyBtn[/lua]
but you didn’t want to declate a function in the first place. That’s your missing bracket.

I’d simplify your 3 touch functions like this

local onBtnTouch = function(event)  
 if event.phase == "release" and event.target.id == "StoryButton" then  
 storyboard.gotoScene("levelselector", "fade", 300)  
  
 elseif event.phase == "release" and event.target.id == "OptionsButton" then  
 audio.play(btnSound)  
 storyboard.gotoScene("options", "crossfade", 300)  
  
 elseif event.phase == "release" and event.target.id == "ArcadeButton" then  
 audio.play(btnSound)  
 storyboard.gotoScene("arcade", "crossfade", 300)  
 end  
end  

[import]uid: 98393 topic_id: 30099 reply_id: 120907[/import]

You’re a life savor Paul_G! I’ll try these during my lunch hours at work. Btw, what are the names of the two games you have in the appstore? [import]uid: 69494 topic_id: 30099 reply_id: 120908[/import]

Are you sure it’s the button and not something else. Storyboard can be tricky sometimes. What was the error message you cut it off? [import]uid: 75779 topic_id: 30099 reply_id: 120487[/import]

Lol that was the error message. My button function looks fine, I don’t understand why it says I need to close the brackets at line 1 (according to the numbers in this forum).

The actual error message probably meant it expected to close the brackets in line 1. As you can see, I closed it in line 15. The button code looks the same in my main game and I had no problem opening it. [import]uid: 69494 topic_id: 30099 reply_id: 120490[/import]

Can someone please help me? The storyboard is the last of my project and I would like to finish this sometime this week so I can test it out on my phone. [import]uid: 69494 topic_id: 30099 reply_id: 120686[/import]

use widget library instead of ui library to see if ui is causing the problems. I’ve already written the code for you to copy/paste. I had strange problems with ui.lua and switched to widget and all the errors went away. I’ve already published 2 games :smiley:

[code]
local widget = require “widget”

local storyBtn

local onPlayTouch = function(event)
– btn function
end

function scene:createScene( event )

local screenGroup = self.view
storyBtn = widget.newButton{
default = “storybtn.png”,
width = 100,
height = 100,
over = “storybtn-over.png”,
onEvent = onPlayTouch,
id = “StoryButton”,
label = “”,
font = “Helvetica”,
labelColor = { default={ 255, 255, 255, 255 }, over={ 255, 255, 255, 255 } },
size = 16,
}
screenGroup:insert(storyBtn)

end
[/code] [import]uid: 98393 topic_id: 30099 reply_id: 120852[/import]

I’m still getting the same error message. This time: "lua:50: ‘}’ expected (to close ‘{’ at line 49) near ‘=’

Maybe I’ll just post the whole code of the main menu:

[lua] --Require the “Widget” library (were using the slider)
local widget = require(“widget”)
–Require the physics library
local physics = require(“physics”)
–Require the UI Library
local ui = require(“ui”)

–Hide the device’s status bar
display.setStatusBar(display.HiddenStatusBar)

local displayGroup = display.newGroup()

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

local btnAnim
local btnSound = audio.loadSound(“btnSound.wav”)
function scene:createScene(event)
local displayGroup = self.view

storyboard.removeScene(“loadmainmenu”)
storyboard.removeScene(“levelselector”)
storyboard.removeScene(“arcade”)
storyboard.removeScene(“options”)

print( “\nmainmenu: createScene event” )

end

function scene:enterScene(event)
local displayGroup = self.view
print(“mainmenu: enterScene event”)

local backgroundImage = display.newImageRect(“mainmenu.png”, 480, 320)
backgroundImage.x = 240; backgroundImage.y = 160
displayGroup:insert(backgroundImage)

local storyBtn

local onPlayTouch = function(event)
if event.phase == “release” then
storyboard.gotoScene(“levelselector”, “fade”, 300)
end
end

storyBtn = widget.newButton{
default.Src = “storybtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “storybtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “StoryButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16
}

storyBtn.x = 240; storyBtn.y = 440
displayGroup:insert(storyBtn)

btnAnim = transition.to(storyBtn, {time=500, y=260, transition=easing.inOutExpo})

local optBtn
local onOptionsTouch = function(event)
if event.phase == “release” then

audio.play(btnSound)
storyboard.gotoScene(“options”, “crossfade”, 300)
end
end

local optBtn

optBtn = widget.newButton{
defaultSrc = “optbtn.png”,
defaultX = 60,
defaultY = 60,
overSrc = “optbtn-over.png”,
overX = 60,
overY = 60,
onEvent = onOptionsTouch,
id = “OptionsButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
}

optBtn.x = 430; optBtn.y = 440
displayGroup:insert(optBtn)

btnAnim = transition.to(optBtn, {time=500, y=280, transition=easing.inOutExpo})

local arcadeBtn

local arcadeBtn
local onOptionsTouch = function(event)
if event.phase == “release” then

audio.play(btnSound)
storyboard.gotoScene(“arcade”, “crossfade”, 300)
end
end

arcadeBtn = widget.newButton{
default.Src = “arcadebtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “arcadebtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “ArcadeButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
}

arcadeBtn.x = 240; arcadeBtn.y = 440
displayGroup:insert(arcadeBtn)

btnAnim = transition.to(arcadeBtn, {time=500, y=260, transition=easing.inOutExpo})

local brutalBtn

local brutalBtn
local onOptionsTouch = function(event)
if event.phase == “release” then

audio.play(btnSound)
storyboard.gotoScene(“brutal”, “crossfade”, 300)
end
end

brutalBtn = widget.newButton{
default.Src = “brutalBtn.png”,
defaultX = 100,
defaultY = 100,
overSrc = “brutalBtn-over.png”,
overX = 100,
overY = 100,
onEvent = onPlayTouch,
id = “BrutalButton”,
text = “”,
font = “Helvetica”,
textColor = {255, 255, 255, 255},
size = 16,
emboss = false
}

brutalBtn.x = 240; brutalBtn.y = 440
displayGroup:insert(brutalBtn)

btnAnim = transition.to(brutalBtn, {time=500, y=260, transition=easing.inOutExpo})

end

function scene:exitScene()
if btnAnim then transition.cancel(btnAnim); end
print(“mainmenu: exitScene event”)
end

function scene:destroyScene(event)
print("((destorying mainmenu’s view))")
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene

[lua]I can’t see what I’m doing wrong here :confused: [import]uid: 69494 topic_id: 30099 reply_id: 120886[/import]

If you need to do something with the widget’s display object (such as place the button into a display group), you need to do so using the object’s .view property. Example:[/lua]
local myButton = widget.newButton{ label=“My Button” }

– WRONG, will produce error:
myGroup:insert( myButton )

– CORRECT: access display group with .view property
myGroup:insert( myButton.view )
[import]uid: 75779 topic_id: 30099 reply_id: 120890[/import]

Hi rmckee282002, you’re wrong on this one! I know,the API is a bit confusing, but you’ll find the change on the widget button api

[NOTE: Deprecated as of build 2012.721—the widget is now the display object]

If you need to do something with the widget’s display object (such as place the button into a display group), you need to do so using the object’s .view property

http://developer.coronalabs.com/reference/index/widgetnewbutton [import]uid: 98393 topic_id: 30099 reply_id: 120893[/import]

neilw711

I don’t know. A closing bracket could be missing on any line, so you should skim the whole file instead of just concentrating on the line when the Interpreter gets an error.
And yeah, comment out the “require ui.lua” I know sounds weird but I got errors with the latest ui.lua. [import]uid: 98393 topic_id: 30099 reply_id: 120895[/import]