attempt to concatenate global 'scene name' (a nil value) How to fix this error

1 --menu.lua

2

3local composer = require(“composer”)

4

5 local scene = composer.newScene()

6

7 local function gotoGame() 

8 end

9

10 local function gotoHighScores()

11  composer.gotoScene(“highscores”)

12 end

13

14       function scene:create(event) 

15–>    local sceneGroup = self.view

            local background = display.newImageRect(sceneGroup, “assets/background.jpg”, 800, 1400)

            background.x = display.contentCenterX

            background.y = display.contentCenterY        

    local title = display.newImageRect(sceneGroup, “play.png”, 500, 80)

    title.x = display.contentCenterX

    title.y = 200

    local text = display.newText(scenegroup, “logo.jpg” )

    local gameText = display.newText(group, “Play”, display.contentCenterX, 700, nill, 44)

    local highScoreText = display.newImageText(sceneGroup, “Highscore”, display.contentCenterX, 810, nil,44)

    gameText:addEventListener(“tap”, gotoGame)

    highScoreText:addEventListener(“tap”, gotoHighScores)

end

local composer = require( “composer” )

local scene = composer.newScene()


– All code outside of the listener functions will only be executed ONCE 

– unless “composer.removeScene()” is called.


– local forward references should go here



– “scene:create()”


function scene:create( event )

  local sceneGroup = self.view

  

  – Initialize the scene here.

  – Example: add display objects to “sceneGroup”, add touch listeners, etc.

end


– “scene:show()”


function scene:show( event )

  local sceneGroup = self.view

  local phase = event.phase

  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

    – Called when the scene is on screen (but is about to go off screen).

    – Insert code here to “pause” the scene.

    – Example: stop timers, stop animation, stop audio, etc.

  elseif ( phase == “did” ) then

    – Called immediately after scene goes off screen.

  end

end


– “scene:destroy()”


function scene:destroy( event )

  local sceneGroup = self.view

  – Called prior to the removal of scene’s view (“sceneGroup”).

  – Insert code here to clean up the scene.

  – Example: remove display objects, save state, etc.

end


– Listener setup


scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


  1. Welcome to the community.
     
  2. Only post questions once.  Multiple postings is a violation and a waste. Those of us who answer questions will see a single posting.  We are actually MORE likely to ignore a multi-post than to answer it.  
     
    Please close this post: https://forums.coronalabs.com/topic/70716-help-attempt-to-concatenate-global-scene-name-a-nil-value/#entry369205
     
     
  3. Please format your code with code blocks:
    formatyourcode.jpg
     
  4. Let me take a look and post back…

Looking at your code, I see you have this twice

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) ...

Additionally, you did NOT return scene (the likely culprit here)

-------------------------------------------------------------------------------- -- Listener setup -------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -------------------------------------------------------------------------------- return scene -- YOU FORGOT THIS

I cleaned up your project, minimized parts of it, and it works fine here:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/10/composer.zip
 
 
For general reference, I have a lot of samples, helper code, libraries etc. for when you get more experienced with Corona:
https://github.com/roaminggamer
 
Also, when you’ve really got a good idea of how to use Corona or if you’re looking for a high-level solution to some common game dev problem, consider looking into SSK2.
 
You might like to look at these composer examples now as I cover a broad range of examples:
https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

  • 1_transitions - Examines basic transitions and allows you to try all of the known transition.
  • 2_eventSequence - Dumps scene transition phases to console so you can understand when they happen and how they relate to transitions.
  • 3_badManagement - Shows example of ‘bad’ (or incorrect) object management.
  • 4_goodManagement - Same as ‘3’ with corrections to properly handle management.
  • 5_frame - Basic app framework using Composer.
  • 6_memory - Shows memory usage examples.
  • 7_custom_transitions - Shows custom transitions and how to make them.
  • 8_objectsInModules - Shows how to manage sprites and other modules in coordination w/ Composer.
  • 9_simple_organization - Examples of how to organize data so it can easily be accessed across scene scopes.
  • 10_change_scene_on_collision - Answer to forums question, “How can I change scenes when an object in my scene collides with another object?”
  • 11_reference_passing - Answer to a forums question, “How do I pass data from one scene to another?”
  • 12_rebuild_playgui - Example of ‘building the scene on each re-entry’ versus just once in ‘create’.
  • 13_textFields - Answer to question in forums, “How do I manage my text fields between scenes?”
  • 14_textFields_as_scene_gates - Changes last example to prevent scene changes unless specific values are in the text fields.
  • 15_android_back_nav - Navigating back to prior scene with back button on Android devices.
  1. Welcome to the community.
     
  2. Only post questions once.  Multiple postings is a violation and a waste. Those of us who answer questions will see a single posting.  We are actually MORE likely to ignore a multi-post than to answer it.  
     
    Please close this post: https://forums.coronalabs.com/topic/70716-help-attempt-to-concatenate-global-scene-name-a-nil-value/#entry369205
     
     
  3. Please format your code with code blocks:
    formatyourcode.jpg
     
  4. Let me take a look and post back…

Looking at your code, I see you have this twice

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) ...

Additionally, you did NOT return scene (the likely culprit here)

-------------------------------------------------------------------------------- -- Listener setup -------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -------------------------------------------------------------------------------- return scene -- YOU FORGOT THIS

I cleaned up your project, minimized parts of it, and it works fine here:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/10/composer.zip
 
 
For general reference, I have a lot of samples, helper code, libraries etc. for when you get more experienced with Corona:
https://github.com/roaminggamer
 
Also, when you’ve really got a good idea of how to use Corona or if you’re looking for a high-level solution to some common game dev problem, consider looking into SSK2.
 
You might like to look at these composer examples now as I cover a broad range of examples:
https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

  • 1_transitions - Examines basic transitions and allows you to try all of the known transition.
  • 2_eventSequence - Dumps scene transition phases to console so you can understand when they happen and how they relate to transitions.
  • 3_badManagement - Shows example of ‘bad’ (or incorrect) object management.
  • 4_goodManagement - Same as ‘3’ with corrections to properly handle management.
  • 5_frame - Basic app framework using Composer.
  • 6_memory - Shows memory usage examples.
  • 7_custom_transitions - Shows custom transitions and how to make them.
  • 8_objectsInModules - Shows how to manage sprites and other modules in coordination w/ Composer.
  • 9_simple_organization - Examples of how to organize data so it can easily be accessed across scene scopes.
  • 10_change_scene_on_collision - Answer to forums question, “How can I change scenes when an object in my scene collides with another object?”
  • 11_reference_passing - Answer to a forums question, “How do I pass data from one scene to another?”
  • 12_rebuild_playgui - Example of ‘building the scene on each re-entry’ versus just once in ‘create’.
  • 13_textFields - Answer to question in forums, “How do I manage my text fields between scenes?”
  • 14_textFields_as_scene_gates - Changes last example to prevent scene changes unless specific values are in the text fields.
  • 15_android_back_nav - Navigating back to prior scene with back button on Android devices.