problem going from one scene to other

hey guys

when my game overs, it takes me to gameOver scene…but it gives me this error

14:34:12.052 ERROR: Runtime error 14:34:12.052 ERROR: nil key supplied for property lookup. 14:34:12.052 stack traceback: 14:34:12.052 [C]: ? 14:34:12.052 ?: in function 'removeEventListener' 14:34:12.052 ?: in function 'removeEventListener' 14:34:12.052 ?: in function 'removeEventListener' 14:34:12.052 C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:335: in function \<C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:328\> 14:34:12.052 ?: in function 'dispatchEvent' 14:34:12.052 ?: in function '\_saveSceneAndHide' 14:34:12.052 ?: in function 'gotoScene' 14:34:12.052 C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:250: in function \<C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:250\> 14:34:12.052 (tail call): ? 14:34:12.052 ?: in function \<?:504\> 14:34:12.052 ?: in function \<?:169\>

my code of my game is this :

local composer = require( "composer" ) local scene = composer.newScene() local physics = require "physics" physics.start() physics.setGravity(0,13) physics.setDrawMode("normal") user = loadsave.loadTable("user.json") -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- time local timeCounter = 0 -- enemies local virus = {} -- enemies table local enemyTravelSpeed = 2000 -- enemy travel speed across the screen local enemySendSpeed = 100 local enemyCounter = 0 local enemyIncrementSpeed = 5 local enemyMaxSendSpeed = 10 -- score properties user.score = 0 local scoreText -- other properties local ball, ground, leftWall, rightWall local ballRadius = 30 -- if isScoringUp is set to true, then, when enemy collides with the ground, score up, else don't score up. local isScoringUp = true local onGameOver -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local backgroundImage = display.newImageRect(sceneGroup,"freePlay/images/Background image.png",800,1400) backgroundImage.x = centerX backgroundImage.y = centerY backgroundImage.width = screenWidth backgroundImage.height = screenHeight scoreText = display.newText(sceneGroup, "Score:0",0,0,\_font,40) scoreText.anchorX = 1 scoreText.x = screenRight - scoreText.width \* 0.1 scoreText.y = screenTop + scoreText.height local function dragMe(event) local self=event.target if event.phase == "began" then display.getCurrentStage():setFocus(self,event.id) --create a touch joint so that gravity doesn't pull the object down self.tempJoint = physics.newJoint( "touch", self, event.x, event.y ) self.isFocus = true self.isFixedRotation = true --stop the object from rotating while being dragged elseif self.isFocus then if event.phase == "moved" then self.tempJoint:setTarget( event.x, event.y ) elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus(self,nil) self.isFixedRotation = false self.isFocus = false self.tempJoint:removeSelf() end end return true end -- to be created local function onPauseTouch( event ) -- body end -- sending enemies local function sendEnemies() -- body -- timeCounter : keeps track of the time in the game, starts at 0 -- enemySendSpeed : will tell us how often to send the enemies, starts at 100 -- enemyCounter : keeps track of the number of enemies on the screen, starts at 0 -- enemyIncrementSpeed : how much to increase the enemy speed, starts at 10 -- enemyMaxSendSpeed : limit the send speed to 400, starts at 400 timeCounter = timeCounter + 1 if ((timeCounter%enemySendSpeed == 0)) then enemyCounter = enemyCounter + 1 enemySendSpeed = enemySendSpeed - enemyIncrementSpeed if enemySendSpeed \>= 50 then enemyIncrementSpeed = 5 end if enemySendSpeed \<= 50 then enemyIncrementSpeed = 2 end if (enemySendSpeed \<= enemyMaxSendSpeed) then enemySendSpeed = enemyMaxSendSpeed end virus[enemyCounter] = display.newImageRect(sceneGroup ,"freePlay/images/virus.png",100,100) virus[enemyCounter].x = math.random(screenLeft + screenWidth \* 0.1, screenRight - screenWidth \* 0.1) virus[enemyCounter].y = screenTop - virus[enemyCounter].height virus[enemyCounter].name = "enemy" physics.addBody(virus[enemyCounter],"dynamic") virus[enemyCounter].isFixedRotation = false transition.to(virus[enemyCounter], {y = screenBottom - virus[enemyCounter].height \* 0.5, time =enemyTravelSpeed, onComplete = function(self) if self ~= nil then display.remove(self); end end }) end end --scoring up local function scoreUp( event ) -- body user.score = user.score + 100 scoreText.text = "Score:".. user.score scoreText.anchorX = 1 scoreText.x = screenRight - scoreText.width \* 0.1 loadsave.saveTable(score,"user.json") end -- onCollision local function onCollision(event) if (event.phase == "began") then if (event.object1.name == "ball" and event.object2.name == "enemy") then print("Game Over1") if event.target.object1 ~= nil then --display.remove(event.target.object1) timer.performWithDelay(10,showBanners(event.object1, event.object2),1) --onGameOver(event.object1, event.object2) end elseif (event.object2.name == "ball" and event.object1.name == "enemy")then print("Game Over2") if event.object2 ~= nil then --display.remove(event.object2) showBanners(event.object2, event.object1) --onGameOver(event.object2, event.object1) end elseif (event.object1.name == "enemy" and event.object2.name == "ground")then if isScoringUp == true then if event.object1 ~= nil then print("Score Up") display.remove(event.object1) scoreUp() end elseif isScoringUp == false then if event.object1 ~= nil then print("No score Up") display.remove(event.object1) scoreUp() end end elseif (event.object1.name == "ground" and event.object2.name == "enemy")then if isScoringUp == true then if event.object2 ~= nil then print("Score Up") display.remove(event.object2) scoreUp() end elseif isScoringUp == false then if event.object2 ~= nil then print("No score Up") display.remove(event.object2) scoreUp() end end end end end local function onGameOver() print("enemies cleared") --ball:removeEventListener("touch",dragMe) end function showBanners(obj1,obj2 ) -- body print("Hey") audio.play(shockSound) transition.pause() physics.pause() Runtime:removeEventListener("enterFrame",sendEnemies) --up banner banner1 = display.newImage(sceneGroup,"freePlay/images/collision/upBanner.png") banner1.x = obj1.x + 50 banner1.y = obj1.y - 180 banner1:scale(0,0) -- down banner banner2 = display.newImage(sceneGroup,"freePlay/images/collision/downBanner.png") banner2.x = obj1.x banner2.y = obj1.y + 180 banner2:scale(0,0) -- right banner banner3 = display.newImage(sceneGroup,"freePlay/images/collision/rightBanner.png") banner3.x = obj1.x + 180 banner3.y = obj1.y banner3:scale(0,0) -- left banner banner4 = display.newImage(sceneGroup,"freePlay/images/collision/leftBanner.png") banner4.x = obj1.x - 180 banner4.y = obj1.y banner4:scale(0,0) -- increasing the scale of ball and banners transition.to(ball,{xScale = 2, yScale = 2, time = 500, onComplete = function () Runtime:removeEventListener("collision",onCollision)end }) transition.to(banner1,{xScale = 1 , yScale = 1, time =200}) transition.to(banner2,{xScale = 1 , yScale = 1, time =200}) transition.to(banner3,{xScale = 1 , yScale = 1, time =200}) transition.to(banner4,{xScale = 1 , yScale = 1, time =200}) -- moving banners off screens timer.performWithDelay(2000, function() transition.to(banner1,{x = screenRight + 200, y = obj1.y - 250, time = 500, alpha = 0, onComplete = function () display.remove(self)end }) transition.to(banner2,{x = screenLeft - 200, y = obj1.y + 250, time = 500 , alpha = 0,onComplete = function () display.remove(self)end }) transition.to(banner3,{x = obj1.x + 250, y = screenBottom + 200, time = 500, alpha =0 ,onComplete = function () display.remove(self)end}) transition.to(banner4,{x = obj1.x - 200, y = screenTop - 250, time = 500, alpha = 0,onComplete = function () display.remove(self)end}) end ) -- removing enemies timer.performWithDelay(3000, function() physics.start() for i = 1, #virus do if virus[i] ~= nil then transition.to(virus[i],{alpha = 0, time = 500, onComplete = function() display.remove(virus[i]); composer.gotoScene("freePlay.gameOver","crossFade",1000) end })--error in this line end end end ,1) end if user.isRedEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/red-white-ball.png",60,60) elseif user.isYellowEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/yellow-white-ball.png",60,60) elseif user.isPurpleEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/purple-white-ball.png",60,60) elseif user.isOrangeEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/orange-white-ball.png",60,60) elseif user.isBlueEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/blue-white-ball.png",60,60) elseif user.isGreenEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/green-white-ball.png",60,60) end ball.x = centerX ball.y = centerY ball.name = "ball" physics.addBody(ball,"dynamic",{radius = ballRadius, bounce = 0.5}) ball:addEventListener("touch",dragMe) ground = display.newRect (sceneGroup,0,0,screenWidth,20) ground.x = centerX ground.y = screenBottom + ground.height \* 0.5 ground:setFillColor(1,1,1) ground.name = "ground" physics.addBody(ground,"static") leftWall = display.newRect (sceneGroup,0,0,20,screenHeight) leftWall.x = screenLeft - leftWall.width \* 0.5 leftWall.y = centerY leftWall:setFillColor(1,1,1) physics.addBody(leftWall,"static") rightWall = display.newRect (sceneGroup,0,0,20,screenHeight) rightWall.x = screenRight + rightWall.width \* 0.5 rightWall.y = centerY rightWall:setFillColor(1,1,1) physics.addBody(rightWall,"static") Runtime:addEventListener("enterFrame" ,sendEnemies) Runtime:addEventListener("collision", onCollision) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) ball:removeEventListener("touch",dragMe) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

error was in composer.gotoScene line

please help 

Solved !!

Solution?

removed ball:removeEventListener from scene:hide function 

Generally speaking you do not need to remove touch and tap listeners. They are usually on display objects and will be taken off screen when a scene changes and removed when the object is destroyed.

Rob

i have one problem 

when i go to gameOver.lua when my game overs with a score of more than 15000 or somewhat like that, and when i reloads tha game, it works slow. It lags. But when my score is less and then i loose that game, when i reloads it, it works good(doesn’t lag).

So is there any problem?

I have posted my code above :) 

This is my gameOver.lua

local composer = require( "composer" ) local widget = require "widget" local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- background local bg local bgOverlay -- scores local scoreOverlay, scoreText, highScoreText --local transitions local moveBallLeft, moveBallRight -- ball local ball -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- local function onButtonTouch( event ) -- body if event.phase == "ended" then local id = event.target.id if id == "main menu" then composer.gotoScene("scene\_play","crossFade") else composer.removeScene("freePlay.freePlay") composer.gotoScene("freePlay.freePlay","crossFade") end end end -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen bg = display.newImageRect(sceneGroup,"freePlay/images/Background image.png",640,1200) bg.x = centerX bg.y = centerY bg.width = screenWidth bg.height = screenHeight bgOverlay = display.newImageRect(sceneGroup, "freePlay/images/gameOver/gameOverBg.png",800,1300) bgOverlay.x = centerX bgOverlay.y = centerY bgOverlay.height = screenHeight scoreOverlay = display.newImageRect(sceneGroup, "freePlay/images/gameOver/scoreOverlay.png",450,140) scoreOverlay.y = screenTop + screenHeight \* 0.2 scoreOverlay.x = centerX scoreText = display.newText(sceneGroup,"",0,0,\_font,80) scoreText.text = "Score:".." "..user.score scoreText.x = scoreOverlay.x scoreText.y = scoreOverlay.y scoreText:setTextColor() btn\_mainMenu = widget.newButton { width = 330 , height = 126, defaultFile = "freePlay/images/gameOver/btn\_mainMenu.png", overFile = "freePlay/images/gameOver/btn\_mainMenu\_over.png", id = "main menu", onEvent = onButtonTouch, label = "Main Menu", fontSize = 50, font = \_font, labelColor = { default = {1,1,1}, over = {1,0.9,1}} } btn\_mainMenu.x = screenLeft + btn\_mainMenu.width \* 0.65 btn\_mainMenu.y = centerY + btn\_mainMenu.height sceneGroup:insert(btn\_mainMenu) btn\_playAgain = widget.newButton { width = 330 , height = 126, defaultFile = "freePlay/images/gameOver/btn\_mainMenu.png", overFile = "freePlay/images/gameOver/btn\_mainMenu\_over.png", id = "play again", onEvent = onButtonTouch, label = "Play Again", fontSize = 50, font = \_font, labelColor = { default = {1,1,1}, over = {1,0.9,1}} } btn\_playAgain.x = btn\_mainMenu.x + btn\_mainMenu.width \* 1.1 btn\_playAgain.y = centerY + btn\_mainMenu.height sceneGroup:insert(btn\_playAgain) if user.score \> 100000000 then scoreText.size = 60 end highScoreText = display.newText(sceneGroup , "High Score:".." "..user.highscore,0,0,\_font,50) highScoreText.x = scoreOverlay.x highScoreText.y = scoreOverlay.y + scoreOverlay.height \* 0.8 highScoreText:setTextColor() if user.score \> user.highscore then print("High score changed ") user.highscore = user.score loadsave.saveTable(user,"user.json") highScoreText.text = "High Score:".." "..user.score highScoreText.x = scoreOverlay.x else print("High Score not changed ") highScoreText.text = "High Score:".." "..user.highscore end if user.isRedEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/red-white-ball.png",60,60) elseif user.isYellowEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/yellow-white-ball.png",60,60) elseif user.isPurpleEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/purple-white-ball.png",60,60) elseif user.isOrangeEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/orange-white-ball.png",60,60) elseif user.isBlueEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/blue-white-ball.png",60,60) elseif user.isGreenEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/green-white-ball.png",60,60) end ball.x = scoreOverlay.x + scoreOverlay.width \* 0.5 ball.anchorX = 1 ball.anchorY = 1 ball.y = scoreOverlay.y - scoreOverlay.height \* 0.5 end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen function moveBallLeft() transition.to(ball,{x = scoreOverlay.x + scoreOverlay.width \* 0.5 ,time = 2000,anchorX = 1,onComplete = moveBallRight}) end function moveBallRight() transition.to(ball,{x = scoreOverlay.x - scoreOverlay.width \* 0.5 ,time = 2000,anchorX = 0,onComplete = moveBallLeft }) end moveBallRight() end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen user.score = 0 loadsave.saveTable(user,"user.json") print("Score set to zero") end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

Are you doing anything different before you go to the gameOver scene? Like turning off listeners, timers, transitions for one but not the other?

Rob

I removed the timers and event listeners ( you can see the code above)
I think it is because of global functions
I have two global functions in gameOver and one in game…it might be the case of memory leak :confused:
Confused.
Btw i have too many queries too be answered by you all…should i ask them in this topic too aur should i post a new tppic?? Firstly we’ll clear this topic​:slight_smile::slight_smile:

That’s not the question I was really asking. I don’t thing gameOver.lua is causing your slow down. It sounds like when you go back to the game scene, you may be doubling up a timer in “freePlay” module or doubling up an enterFrame listener that could be killing your performance. It could be the globals, but unless you’re using the same function names. You are also not stopping your move ball transition. In this scene.

If you feel you’re leaking memory you should probably put some prints in your code that prints your memory value.

As for other topics, please ask in new threads.

Thanks

Rob

How can i print memory values ??

print( "Texture Memory", string.format("%0.2fMB", system.getInfo( "textureMemoryUsed" ) / (1024 \* 1024) ) ) print( "Lua Memory", string.format( "%0.2fMB", collectgarbage("count") / 1024 ) )

You can see my sendEnemies function in game scene…there is math.random usage…so it possible to spawn enemies where my player is there??
Like my ball is my player…it is draggable…so if user drags the ball to the right side of the screen, so enemies should be spawning half the time from right and vice versa.

anybody??

what is lua memory and texture memory

im getting 9.55 mb texture memory and 0.44 lua memory…is it okay ??

https://forums.coronalabs.com/topic/16134-max-texture-memory/

Lua memory is memory allocated from the devices main pool of memory. It is where strings, numbers, and tables get their memory.

Texture memory is memory used by the Graphics Processing Unit (GPU) to manage the images being pipelined to the screen. Depending on the device, the GPU may borrow main memory to supplement its own. In Corona Terms, this is memory used by display.newImage() and display.newImageRect() and similar.

Images take up as much memory as multiplying their dimensions by 4. Thus a 64 x 128 pixel image is 32,768 bytes of texture memory or 32Kbytes (Kilobytes = 1024 bytes) or 0.032MBytes (Mega bytes = 1024 Kilo bytes = 1 million plus bytes.)  A 2048x2048 sprite sheet takes up 16 megabytes of memory.

Most devices have at least 256 megabytes of memory. Most modern devices are 512 megabytes up to 2 gigabytes (2048 megabytes). Now of course your app doesn’t get all of that memory. The operating system uses a good chunk. There’s no good way to measure, but keeping your app between 50 megabytes and 200 megabytes.  So 9 isn’t much at all. And for the Lua memory 0.44 is pretty low. Though unless you have some really big data structures with lots of data, the Lua memory shouldn’t get very high at all.

Rob

My game still lags when score is bigger
Sometimes, after losing, when going to gameOver scene and hitting play again button, the gameOver scene doesnt get removed…the gameOver scene doesnt get removed but the game works in background…
Should i use composer overlay instead??

Using an overlay won’t change anything. What ever is causing your slow down will continue to do so.

You need to find out what’s causing the slow down.  Does your memory increase over time?

Look at the code where you determine if the score is above a certain value. Make sure to kill your transitions running in your gameOver scene. Use composer.removeScene() to remove the gameOver scene (remember you can’t remove a scene if you’re in it, so wait until you’re back to your game scene to remove gameOver.

it jumps from 13 mb 48 mb…when in game, it remains 12mb throughout the game, but after it goes to gameOver scene, it goes directly to 48 mb .

And when you go back to the game? Back to game over? Back to the game?