Contact button not switching views/Lua files

I was wondering if someone could look at my code and tell me why my contact button isn’t working. When I click the play button it switches the the level1.lua file but when I click on the contact button it freezes the corona simulator and does not switch.

[code]



– menu.lua


local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

– include Corona’s “widget” library
local widget = require “widget”


– forward declarations and other locals
local playBtn

– ‘onRelease’ event listener for playBtn
local function onPlayBtnRelease()

– go to level1.lua scene
storyboard.gotoScene( “level1”, “fade”, 500 )

return true – indicates successful touch
end

local contactBtn

– ‘onRelease’ event listener for contactBtn
local function oncontactBtnRelease()

– go to level1.lua scene
storyboard.gotoScene( “contact”, “fade”, 500 )

return true – indicates successful touch
end


– BEGINNING OF YOUR IMPLEMENTATION

– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.


– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view

– display a background image
local background = display.newImageRect( “bkg_clouds.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0

– create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( “logo2.png”, 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 100

– create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
label=“Play Now”,
labelColor = { default={255}, over={128} },
default=“button.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = onPlayBtnRelease – event listener function
}

– create a widget button (which will loads contact.lua on release)
contactBtn = widget.newButton{
label=“contact”,
labelColor = { default={255}, over={128} },
default=“button.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = oncontactBtnRelease – event listener function
}
playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight - 125

contactBtn:setReferencePoint( display.CenterReferencePoint )
contactBtn.x = display.contentWidth*0.5
contactBtn.y = display.contentHeight - 75
– all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
group:insert( contactBtn )
end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view

– INSERT code here (e.g. start timers, load audio, start listeners, etc.)

end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view

– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)

end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view

if playBtn then
playBtn:removeSelf() – widgets must be manually removed
playBtn = nil
end

if contactBtn then
contactBtn:removeSelf() – widgets must be manually removed
contactBtn = nil
end
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene

[/code] [import]uid: 6134 topic_id: 24213 reply_id: 324213[/import]

Forgive me for bumping my own thread but I need someone help. I have two apps on apple’s app store right now that I wanted to add redo in corona. I have all the lua files done. But all I need to do is understand how to add simply buttons to go back and forth between lua/scene files. [import]uid: 6134 topic_id: 24213 reply_id: 98073[/import]

please forgive me again for bumping this thread. I really need help with this. I need to add 7 buttons to this menu page above. It must be some easy why of doing this. [import]uid: 6134 topic_id: 24213 reply_id: 98296[/import]

Your code looks ok to me, but I have not used widgets with storyboard, so maybe there is some nuance there.

I would put a “print” statement in your “oncontactBtnRelease” function and verify the function is really being called when you tap the contact button. If so, I would verify that “contact.lua” exists in your folder. [import]uid: 27976 topic_id: 24213 reply_id: 98299[/import]

Can some explain to me how to write a print statement to verify contact is being called. contact.lua does exist in my folder. [import]uid: 6134 topic_id: 24213 reply_id: 98567[/import]

Sure. Try this:

local function oncontactBtnRelease()  
  
 print("Made it to oncontactBtnRelease function")  
  
 -- go to level1.lua scene  
 storyboard.gotoScene( "contact", "fade", 500 )  
  
 return true -- indicates successful touch  
end  

You should see “Made it to oncontactBtnRelease function” in Console/Terminal on a Mac or Corona Simulator Output on a PC.

And remember files are case-sensitive, so ensure the file is “contact.lua” and not “Contact.lua”. [import]uid: 27976 topic_id: 24213 reply_id: 98589[/import]