I’m trying to use “params” in composer to pass information to another scene (depending on which button the user selected) and then use the params to require a file. Initially this was working when I was doing it in scene:create (picture.lua), but now that I moved it to scene:show I’m getting the error “attempt to index local ‘params’ (a nil value)” . Is there something I’m doing wrong or is this a bug? I simplified all the files (below) and still had the error with today’s daily build. Thanks for the help.
main.lua
[lua]
local composer = require( “composer” )
local widget = require( “widget” )
local function onButtonSelect(event)
firstVisit = false
local options = {
effect = “fade”,
time = 500,
params = {
requiredFile = event.target.fileName
}
}
composer.gotoScene( “picture”, options )
return true
end
local button1 = widget.newButton
{
label = “button 1”,
onEvent = onButtonSelect,
emboss = false,
--properties for a rounded rectangle button…
shape=“roundedRect”,
width = 200,
height = 40,
cornerRadius = 2,
fillColor = { default={ 1, 0, 0, 1 }, over={ 1, 0.1, 0.7, 0.4 } },
strokeColor = { default={ 1, 0.4, 0, 1 }, over={ 0.8, 0.8, 1, 1 } },
strokeWidth = 4
}
button1.x = display.contentCenterX
button1.y = 100
button1.fileName = “file1”
local button2 = widget.newButton
{
label = “button 2”,
onEvent = onButtonSelect,
emboss = false,
--properties for a rounded rectangle button…
shape=“roundedRect”,
width = 200,
height = 40,
cornerRadius = 2,
fillColor = { default={ 1, 0, 0, 1 }, over={ 1, 0.1, 0.7, 0.4 } },
strokeColor = { default={ 1, 0.4, 0, 1 }, over={ 0.8, 0.8, 1, 1 } },
strokeWidth = 4
}
button2.x = display.contentCenterX
button2.y = 200
button2.fileName = “file2”
[/lua]
picture.lua
[lua]
local composer = require( “composer” )
local scene = composer.newScene()
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
--PARAMETERS passed in from the menu
local params = event.params
–REQUIRE the MODULE
local m = require (params.requiredFile)
if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == “did” ) then
– Called when the scene is now on screen.
– Insert code here to make the scene come alive.
– Example: start timers, begin animation, play audio, etc.
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
file1.lua
[lua]
local t = {}
print( “file1.lua has been loaded.” )
return t
[/lua]
file2.lua
[lua]
local t = {}
print( “file2.lua has been loaded.” )
return t
[/lua]