I am building my first app and I’m having a hard time combining 2 of your basic tutorials. I simply want to have a button that will move from one scene to another. I created a Storyboard template, then from main.lua I call storyboard.gotoScene( "welcomeScreen" ) which works fine. From then on, on welcomeScreen.lua, I am trying to use the basic example of creating a button and adding a eventListener to it but I get the error message below. Since the Storyboard template is so basic, I can’t seem to understand what’s the issue here.
Here’s the error:
[text]
Runtime error
…ropbox/Projects/Corona/SpellingApp/welcomeScreen.lua:51: attempt to index local ‘wordSearchButton’ (a nil value)
stack traceback:
[C]: ?
…ropbox/Projects/Corona/SpellingApp/welcomeScreen.lua:51: in main chunk
[C]: in function ‘require’
?: in function ‘gotoScene’
…/rafael/Dropbox/Projects/Corona/SpellingApp/main.lua:12: in main chunk
Runtime error: …ropbox/Projects/Corona/SpellingApp/welcomeScreen.lua:51: attempt to index local ‘wordSearchButton’ (a nil value)
stack traceback:
[C]: ?
…ropbox/Projects/Corona/SpellingApp/welcomeScreen.lua:51: in main chunk
[C]: in function ‘require’
?: in function ‘gotoScene’
…/rafael/Dropbox/Projects/Corona/SpellingApp/main.lua:12: in main chunk
[/text]
And here’s the code for welcomeScreen.lua:
-----------------------------------------------------------------------------------------
--
-- welcomeScreen.lua
-- by Rafael Gaino on March 7th, 2012
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
--------------------------------------------
local wordSearchButton
-----------------------------------------------------------------------------------------
-- 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 screenGroup = self.view
wordSearchButton = display.newImage( "images/buttons/WordSearchButton.png" )
wordSearchButton.x = 150
wordSearchButton.y = display.contentHeight/2
screenGroup:insert( wordSearchButton )
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
end
-- Listeners
function wordSearchButton:tap( event )
print("wordSearchButton tapped")
end
wordSearchButton:addEventListener( "tap", wordSearchButton )
-----------------------------------------------------------------------------------------
-- 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
[import]uid: 41579 topic_id: 22970 reply_id: 322970[/import]