storyboard problem

hey everybody i am having a little problem with storyboard, on my menu scene i am displaying these letters and adding physics properties to them, when i then switch to my game scene, the actual image of the letter is not there but the physics body is there but does not interfere with the game scene at all, the reason for this is that i am usng physics editor. i then tried removing the display object when switching scenes by using 

display.remove()

the letters physics bodies stoped showing up on the game scene but another problem occured. When i switched back to the menu scene from my game scene, the simulator came up with an ERROR saying

attempt to call method Menu.lua257: addEventLIstener(a nil value)  

Is there anything i can do to fix this? can you please elp me, thanks. Hope you can help!:slight_smile:

The menu page can be found below. 

-- Description:  -- -- Version: 1.0 -- Managed with http://CoronaProjectManager.com -- -- Copyright 2013 Harry Newton. All Rights Reserved. --  local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require "widget-v1" widget.setTheme("theme\_ios") local physicsData = (require "BalloonTitle").physicsData(1.0) local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY) local cw, ch = display.contentWidth, display.contentHeight local physics = require "physics" physics.start() physics.setGravity(0,0.2) physics.setDrawMode("hybrid")     local function buttonHit()         storyboard.gotoScene ( "Game2", { effect = "fade" } ) display.remove(S) display.remove(T) display.remove(i) display.remove(C) display.remove(K) display.remove(Y) display.remove(B) display.remove(A) display.remove(L) display.remove(L2) display.remove(O) display.remove(O2) display.remove(N) display.remove(S2)     end -- Called when the scene's view does not exist: function scene:createScene( event )         local group = self.view          local menuBackground = display.newImage("menuBackground.jpg")       menuBackground.x = centerX        menuBackground.y = 240     group:insert(menuBackground)                                   local Play = widget.newButton {style = "blue2Large",label = "Play", onRelease = buttonHit}          Play.x = 160           Play.y = 240           group:insert(Play)             options = widget.newButton {style = "blue2Large",label = "Options", onRelease = buttonHit}   options.x = centerX   options.y = Play.y  + 70   group:insert(options)                                  credits = widget.newButton {style = "blue2Large",label = "Credits", onRelease = buttonHit} credits.x = centerX credits.y = options.y  + 70  group:insert(credits)                                                           local wallL = display.newRect( -ox, -oy,1.5, ch+oy+oy ) wallL.isVisible = false physics.addBody(wallL, "static", { bounce=0.6, friction=1.0 } ) group:insert(wallL) local wallR = display.newRect( cw-1.5+ox, -oy, 1.5, ch+oy+oy )    wallR.isVisible = false   physics.addBody(wallR, "static", { bounce=0.6, friction=1.0 } ) group:insert(wallR) local wallB = display.newRect( -ox, ch-1.5+oy, cw+ox+ox, 2 ) wallB.isVisible = false physics.addBody(wallB, "static", { bounce=0.6, friction=1.0 } ) group:insert(wallB) local wallT = display.newRect( -ox, -oy, cw+ox+ox, 1.5 ) wallT.isVisible = false physics.addBody(wallT, "static", { bounce=0.6, friction=1.0 } ) group:insert(wallT)      local Letters = display.newGroup() group:insert(Letters) S = display.newImage(Letters,"S.png") physics.addBody(S,"dynamic",physicsData:get("S") ) S:setFillColor(116, 255, 233) group:insert(S)  T = display.newImage(Letters,"T.png") T.x = S.x +42 physics.addBody(T,"dynamic",physicsData:get("t") ) T:setFillColor(255, 155, 30) group:insert(T)  i = display.newImage(Letters,"i.png") i.x = T.x + 36 physics.addBody(i,"dynamic",physicsData:get("i") ) i:setFillColor(93, 251, 0) group:insert(i)  C = display.newImage(Letters,"C.png") C.x = i.x + 42  physics.addBody(C,"dynamic",physicsData:get("C") ) C:setFillColor(100, 0, 111) group:insert(C) K = display.newImage(Letters,"K.png") K.x = C.x + 42  physics.addBody(K,"dynamic",physicsData:get("K") ) K:setFillColor(246, 255, 218) group:insert(K)  Y = display.newImage(Letters,"Y.png") Y.x = K.x + 40 physics.addBody(Y,"dynamic",physicsData:get("Y") ) Y:setFillColor(255, 40, 145) group:insert(Y)  B = display.newImage(Letters,"B.png") B.x = S.x - 11 B.y = S.y +59 physics.addBody(B,"dynamic",physicsData:get("B") ) B:setFillColor(230, 255, 37) group:insert(B)  A = display.newImage(Letters,"A.png") A.x = B.x + 43 A.y = B.y physics.addBody(A,"dynamic",physicsData:get("A") ) A:setFillColor(202, 255, 69) group:insert(A)  L = display.newImage(Letters,"L.png") L.x = A.x + 37 L.y = B.y physics.addBody(L,"dynamic",physicsData:get("L") )     L:setFillColor(46, 128, 255)   group:insert(L)        L2 = display.newImage(Letters,"L2.png") physics.addBody(L2,"dynamic",physicsData:get("L2")) L2:setFillColor(255, 251, 0) L2.x = L.x + 30 L2.y = B.y         group:insert(L2)  O = display.newImage(Letters,"O.png")   O.x = L2.x + 40 O.y = B.y physics.addBody(O,"dynamic",physicsData:get("O")) O:setFillColor(232, 0, 229) group:insert(O) O2 = display.newImage(Letters,"O2.png") O2.x = O.x + 40 O2.y = B.y physics.addBody(O2,"dynamic",physicsData:get("O2")) O2:setFillColor(48, 8, 255) group:insert(O2)  N = display.newImage(Letters,"N.png") N.x = O2.x + 37 N.y = B.y physics.addBody(N,"dynamic",physicsData:get("N")) N:setFillColor(0, 240, 71) group:insert(N)  S2 = display.newImage(Letters,"S2.png") S2.x = N.x + 37 S2.y = B.y physics.addBody(S2,"dynamic",physicsData:get("S2")) S2:setFillColor(74, 255, 251) group:insert(S2)         end local function hitLetter(event)      local obj = event.target local phase = event.phase if phase == "began" then          obj:applyLinearImpulse(0,-5,obj.x,obj.y)      end end -- Called immediately after scene has moved onscreen: function scene:enterScene( event )         local group = self.view        S:addEventListener("touch",hitLetter) T:addEventListener("touch",hitLetter) i:addEventListener("touch",hitLetter) C:addEventListener("touch",hitLetter) K:addEventListener("touch",hitLetter) Y:addEventListener("touch",hitLetter) B:addEventListener("touch",hitLetter) A:addEventListener("touch",hitLetter)  L:addEventListener("touch",hitLetter)  L2:addEventListener("touch",hitLetter)  O:addEventListener("touch",hitLetter)  O:addEventListener("touch",hitLetter)  O2:addEventListener("touch",hitLetter)  N:addEventListener("touch",hitLetter)  S2:addEventListener("touch",hitLetter) end -- Called when scene is about to move offscreen: function scene:exitScene( event )         local group = self.view             S:removeEventListener("touch",hitLetter) T:removeEventListener("touch",hitLetter) i:removeEventListener("touch",hitLetter) C:removeEventListener("touch",hitLetter) K:removeEventListener("touch",hitLetter) Y:removeEventListener("touch",hitLetter) B:removeEventListener("touch",hitLetter) A:removeEventListener("touch",hitLetter)  L:removeEventListener("touch",hitLetter)  L2:removeEventListener("touch",hitLetter)  O:removeEventListener("touch",hitLetter)  O:removeEventListener("touch",hitLetter)  O2:removeEventListener("touch",hitLetter)  N:removeEventListener("touch",hitLetter)  S2:removeEventListener("touch",hitLetter) end -- Called prior to the removal of scene's "view" (display group) function scene:destroyScene( event )         local group = self.view         --      INSERT code here (e.g. remove listeners, widgets, save state, etc.) 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 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  

adding on to my problem

when i also switch from the game scene to the menu scene the letters seem to not be there/ dissapeared.

can someone please reply!?!?!. i really need help

Please do not post the same post multiple times.  I’ve removed your other version of this.

First, what is line 257?  Did you copy/paste that message or did you type it?

Next, you do not need to do these removes:

local function buttonHit()         storyboard.gotoScene ( "Game2", { effect = "fade" } ) display.remove(S) display.remove(T) display.remove(i) display.remove© display.remove(K) display.remove(Y) display.remove(B) display.remove(A) display.remove(L) display.remove(L2) display.remove(O) display.remove(O2) display.remove(N) display.remove(S2)     end

And you’re not nil’ing them out either.  Since they are inserted into the scene’s view, they will be transitioned off screen when the gotoScene() gets called and destroyed if/when the scene is purged.  If you are doing this because when you come back to the scene, it’s not be reset correctly, then see this tutorial:  http://www.coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

Next, this block of code (and the others like it)

 O = display.newImage(Letters,"O.png")   ... group:insert(O)

Display objects can only be in one group at once.  When you call display.newImage and pass a group as the first parameter, the object is put in that group.  When you then call group:insert(O) you are taking it out of the Letters group and directly putting it in the scene’s view “group”.  I suspect what you really want to do is not do these group:inserts() for things you are putting in the Letters group, just make sure the Letters group is inserted into group (which I believe you have done)

All of your letters are Global variables.  This is a problematic technique.  At the top of the module add a line like:

local O, T, i, C, K

etc. for all of those variables.  The lower case i is problematic because if you use it in other scenes as an index variable to an array and it’s global there too, you would stomp on this object.

Now for the grand finale.  There reason why you are getting this error is your touch handler.  Corona’s “touch” event generates at least two calls to your event handler, possibly more if they person moves their finger.  There is a “began” phase and an “ended” phase.  Since you are not testing for these event phases, your

        storyboard.gotoScene ( "Game2", { effect = "fade" } ) display.remove(S) display.remove(T) display.remove(i) ...

gets executed at least twice.  You will try to goto Game2 twice.  The first time it removes, S, T, i etc.  The second time, they no longer exist and you get an error.  I would recode that function to read:

local function buttonHit( event )

     if event.phase == “ended” then

           storyboard.gotoScene( “Game2”, { effect = “fade” } )

     end

     return true

end

and see if that helps.

Rob

hey rob, i have followed the tutorial video that you have given me, and i ran into a problem. i tried using the 

storyboard.removeScene("Menu")  

in the buttonHit, in the Menu file and when i switch from the menu screen to the game scene and back to the Menu scene, the letters seem to double very time i go back to the menu scene, i don’t think i followed your tutorial probably, how can i fix this? by the way every bit of other advice you have given me has worked except for this part.

Hazza

You probably should not do a removeScene() in the scene you’re trying to remove.  Put the removeScene() just before the gotoScene() of the scene you’re trying to goto.  For instance if you are in game and going to menu:

storyboard.removeScene(“menu”)

storyboard.gotoScene(“menu”)

But likely you are not getting things in the display group some how.

Rob

adding on to my problem

when i also switch from the game scene to the menu scene the letters seem to not be there/ dissapeared.

can someone please reply!?!?!. i really need help

Please do not post the same post multiple times.  I’ve removed your other version of this.

First, what is line 257?  Did you copy/paste that message or did you type it?

Next, you do not need to do these removes:

local function buttonHit()         storyboard.gotoScene ( "Game2", { effect = "fade" } ) display.remove(S) display.remove(T) display.remove(i) display.remove© display.remove(K) display.remove(Y) display.remove(B) display.remove(A) display.remove(L) display.remove(L2) display.remove(O) display.remove(O2) display.remove(N) display.remove(S2)     end

And you’re not nil’ing them out either.  Since they are inserted into the scene’s view, they will be transitioned off screen when the gotoScene() gets called and destroyed if/when the scene is purged.  If you are doing this because when you come back to the scene, it’s not be reset correctly, then see this tutorial:  http://www.coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

Next, this block of code (and the others like it)

 O = display.newImage(Letters,"O.png")   ... group:insert(O)

Display objects can only be in one group at once.  When you call display.newImage and pass a group as the first parameter, the object is put in that group.  When you then call group:insert(O) you are taking it out of the Letters group and directly putting it in the scene’s view “group”.  I suspect what you really want to do is not do these group:inserts() for things you are putting in the Letters group, just make sure the Letters group is inserted into group (which I believe you have done)

All of your letters are Global variables.  This is a problematic technique.  At the top of the module add a line like:

local O, T, i, C, K

etc. for all of those variables.  The lower case i is problematic because if you use it in other scenes as an index variable to an array and it’s global there too, you would stomp on this object.

Now for the grand finale.  There reason why you are getting this error is your touch handler.  Corona’s “touch” event generates at least two calls to your event handler, possibly more if they person moves their finger.  There is a “began” phase and an “ended” phase.  Since you are not testing for these event phases, your

        storyboard.gotoScene ( "Game2", { effect = "fade" } ) display.remove(S) display.remove(T) display.remove(i) ...

gets executed at least twice.  You will try to goto Game2 twice.  The first time it removes, S, T, i etc.  The second time, they no longer exist and you get an error.  I would recode that function to read:

local function buttonHit( event )

     if event.phase == “ended” then

           storyboard.gotoScene( “Game2”, { effect = “fade” } )

     end

     return true

end

and see if that helps.

Rob

hey rob, i have followed the tutorial video that you have given me, and i ran into a problem. i tried using the 

storyboard.removeScene("Menu")  

in the buttonHit, in the Menu file and when i switch from the menu screen to the game scene and back to the Menu scene, the letters seem to double very time i go back to the menu scene, i don’t think i followed your tutorial probably, how can i fix this? by the way every bit of other advice you have given me has worked except for this part.

Hazza

You probably should not do a removeScene() in the scene you’re trying to remove.  Put the removeScene() just before the gotoScene() of the scene you’re trying to goto.  For instance if you are in game and going to menu:

storyboard.removeScene(“menu”)

storyboard.gotoScene(“menu”)

But likely you are not getting things in the display group some how.

Rob