Composer not working as expected

I am trying out composer with the following code

--main.lua local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event )     local sceneGroup = self.view     local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )     background:setFillColor( 1, 1, 1 )     sceneGroup:insert( background ) end scene:addEventListener( "create", scene ) return scene

However, it gives me a black screen. Did I miss something?

From what I understand you are trying to create it in main.lua. Create a new file and name if my_scene.lua (or something) and move all the code to that file. Then from main.lua use this code to open the scene:

local composer = require( "composer" ) composer.gotoScene( "my\_scene" )

Let me know if it works,

Best regards,

Tomas

main.lua should never be a scene file.  It should require composer and then call composer.gotoScene(). Your scene file should be in some other file that you provide as an option to gotoScene.

main.lua:

local composer = require( "composer" ) --- rest of your main.lua composer.gotoScene( "menu" )

menu.lua:

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event )     local sceneGroup = self.view     local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )     background:setFillColor( 1, 1, 1 )     sceneGroup:insert( background ) end scene:addEventListener( "create", scene ) return scene

Thanks guys, it works now.
But what other stuff should we normally include in the main.lua file? (Except requiring composer and goToScene)

From what I understand you are trying to create it in main.lua. Create a new file and name if my_scene.lua (or something) and move all the code to that file. Then from main.lua use this code to open the scene:

local composer = require( "composer" ) composer.gotoScene( "my\_scene" )

Let me know if it works,

Best regards,

Tomas

main.lua should never be a scene file.  It should require composer and then call composer.gotoScene(). Your scene file should be in some other file that you provide as an option to gotoScene.

main.lua:

local composer = require( "composer" ) --- rest of your main.lua composer.gotoScene( "menu" )

menu.lua:

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event )     local sceneGroup = self.view     local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )     background:setFillColor( 1, 1, 1 )     sceneGroup:insert( background ) end scene:addEventListener( "create", scene ) return scene

Thanks guys, it works now.
But what other stuff should we normally include in the main.lua file? (Except requiring composer and goToScene)