Hello,
in a very simple composer app, I’m consistently getting a “bad argument #1 to ‘unpack’ (table expected, got nil)”, whenever an event handling function is called.
I’ve tried everything I’ve thougth of… it happens running on the simulator, but I also compiled it for windows and exactly the same result.
I’ve reduced the code to this:
local composer = require( "composer" ) local scene = composer.newScene() local math = require "math" -- include Corona's "widget" library local widget = require "widget" local \_gW = display.contentWidth local \_gH = display.contentHeight local \_gFontNormal = \_gW / 16 ---------------------------------- local screenBtn local screenBtn2 local logo local function screenTouchListener( event ) print("W") end local function screen2TouchListener( event ) print("WWWW") composer.gotoScene( "level1", "fade", 1000 ) return true end local function frameUpdate () introd.y = introd.y - 3 -- es introd,y - 0.7 y -2 mientras se toca la pantalla if introd.y \< (\_gH \* -1.2) then logo.isVisible = true screenBtn.isVisible = false screenBtn2.isVisible = true end end function scene:create( event ) local sceneGroup = self.view introd = display.newText { text = "This is a text that will scroll by the screen etc etc lorem ipsum ... whatever", width = \_gW / 1.5, x = \_gW / 2, y = \_gH \* 2, font = native.newFont("MoriaCitadel.TTF"), align = "center", fontSize = \_gFontNormal / 1.3 } introd:setTextColor(0.2,0.2,0.7) logo = display.newImageRect("LOGO2.png", \_gW, \_gH) logo.x = \_gW / 2 logo.y = \_gH / 2 logo.isVisible = false screenBtn = widget.newButton { shape = "rect", fillColor = {default = { 0,0,0}}, width=\_gW, -- \* 2, height=\_gH, -- \* 2, label = "no text really needed", x = \_gW / 2, y = \_gH / 2 } screenBtn.isVisible = true screenBtn2 = widget.newButton { shape = "rect", fillColor = {default = { 0,0,0}}, width=\_gW, -- \* 2, height=\_gH, -- \* 2, label = "same as above", x = \_gW / 2, y = 100 --\_gH / 7 } screenBtn2.isVisible = false sceneGroup:insert( screenBtn ) sceneGroup:insert( screenBtn2 ) sceneGroup:insert( introd ) sceneGroup:insert( logo ) end function scene:show( event ) local phase = event.phase if phase == "will" then elseif phase == "did" then Runtime:addEventListener( "enterFrame", frameUpdate ) screenBtn:addEventListener( "touch", screenTouchListener ) screenBtn2:addEventListener( "touch", screen2TouchListener ) end end function scene:hide( event ) if event.phase == "will" then Runtime:removeEventListener( "enterFrame", frameUpdate ) elseif event.phase == "did" then end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene
The thing is, if the user touches the screen, so screenTouchListener (or screen2TouchListener) is called, I get the mentioned error.
Any advice most welcome.
Thanks in advance,
jaime
