Attempt to call upvalue 'gameOver' (a nil value)

Hi i have problem, i want when gameOver function hit, go to menu scene. But it aint working. ;( HELP
 

local f = timer.performWithDelay( 500, addNewObject, 0 )         gameOverGroup = display.newGroup() end



local function gameOver()     gameOverGroup:insert(gameOver)     f.stop()     gameOverGroup:removeSelf()     physics.stop()     composer.gotoScene( "menu", "fade", 500 ) end

local f generate me new object on screen, but i want it too be removed and as in gameOver go to “menu scene”

here is addNewObject function;
 

local function addNewObject()local startX = math.random(display.contentWidth\*0.1,display.contentWidth\*0.9) local a = math.random(1,12) if(a\<=5)then local rock = display.newImage( "rock.png", startX, -300) gameOverGroup:insert(rock) physics.addBody( rock ) rock.enterFrame = offscreen Runtime:addEventListener( "enterFrame", rock ) rock:addEventListener( "touch", rockTouched ) elseif(a==12)then local b=math.random(1,5) if (b==1) then g="bad-blue.png" elseif(b==2)then g="bad-green.png" elseif(b==3)then g="bad-purple.png" elseif(b==4)then g="bad-red.png" else g="bad-yellow.png" end local badjelly = display.newImage(g, startX, -300) gameOverGroup:insert(badjelly) physics.addBody( badjelly ) badjelly.enterFrame = offscreen Runtime:addEventListener( "enterFrame", badjelly ) badjelly:addEventListener( "touch", badJellyTouched ) elseif(a==10)then local jar = display.newImage( "jar.png", startX, -300) gameOverGroup:insert(jar) physics.addBody( jar ) jar.enterFrame = offscreen Runtime:addEventListener( "enterFrame", jar ) jar:addEventListener( "touch", jarTouched ) elseif(a==11)then local powerJelly = display.newImage( "Power Jelly.png", startX, -300) gameOverGroup:insert(powerJelly) physics.addBody( powerJelly ) powerJelly.enterFrame = offscreen Runtime:addEventListener( "enterFrame", powerJelly ) powerJelly:addEventListener( "touch", superJellyTouched ) else local b=math.random(1,5) if (b==1) then g="jelly-blue.png" elseif(b==2)then g="jelly-green.png" elseif(b==3)then g="jelly-purple.png" elseif(b==4)then g="jelly-red.png" else g="jelly-yellow.png" end local jelly = display.newImage(g, startX, -300) gameOverGroup:insert(jelly) physics.addBody( jelly ) jelly.enterFrame = jellyoffscreen Runtime:addEventListener( "enterFrame", jelly ) jelly:addEventListener( "touch", jellyTouched ) end end need help.
  1. Please format your future code posts.

formatyourcode.jpg

  1. You can’t have a function and a variable with the same name (gameOver) within the same scope:

    local function gameOver() – FUNCTION gameOverGroup:insert(gameOver) – gameOver is a FUNCTION, but insert() takes a variable f.stop() gameOverGroup:removeSelf() physics.stop() composer.gotoScene( “menu”, “fade”, 500 ) end

Also, what are you trying to do there.  I can’t puzzle it out.

This may get your further, but I fear there may be more problems:

local function gameOver() -- FUNCTION f.stop() display.remove( gameOverGroup ) physics.pause() -- Better to pause physics than to stop it. -- Read the docs:https://docs.coronalabs.com/daily/api/library/composer/gotoScene.html -- You were not calling gotoScene correctly composer.gotoScene( "menu", { effect = "fade", time = 500 } ) end

As noted above, you need to go back and re-read the docs more carefully.  You’ not using some of these functions and methods correctly.

https://docs.coronalabs.com/daily/api/

  1. Please format your future code posts.

formatyourcode.jpg

  1. You can’t have a function and a variable with the same name (gameOver) within the same scope:

    local function gameOver() – FUNCTION gameOverGroup:insert(gameOver) – gameOver is a FUNCTION, but insert() takes a variable f.stop() gameOverGroup:removeSelf() physics.stop() composer.gotoScene( “menu”, “fade”, 500 ) end

Also, what are you trying to do there.  I can’t puzzle it out.

This may get your further, but I fear there may be more problems:

local function gameOver() -- FUNCTION f.stop() display.remove( gameOverGroup ) physics.pause() -- Better to pause physics than to stop it. -- Read the docs:https://docs.coronalabs.com/daily/api/library/composer/gotoScene.html -- You were not calling gotoScene correctly composer.gotoScene( "menu", { effect = "fade", time = 500 } ) end

As noted above, you need to go back and re-read the docs more carefully.  You’ not using some of these functions and methods correctly.

https://docs.coronalabs.com/daily/api/