Composer not working

hi im trying to switch scene from the main too another scene and it doesnt work i get lots of errors, here its my code 

main :

 local composer = require(“composer”)

composer.gotoScene (“home”,options )

home 

composer = require(“composer”) 

widget = require(“widget”)

device_width = display.contentWidth --larghezza in pixel dello schermo del tel

device_height = display.contentHeight --altezza in pixel dello schermo del tel

local sfondo = display.newImageRect( “Sfondi/menu2.png”,device_width,device_height)

sfondo.x= device_width/2

sfondo.y= device_height/2

ty all 

https://docs.coronalabs.com/guide/system/composer/index.html

main is correct! You have to use the Scene Template in your home to create a valid scene in it. Pixec left the link above for you to take the scene code template and insert it into your home.

 i did and i stil get this error https://gyazo.com/da16a0f8c70d711523b452c62c813085 my menu2.lua file is this :

local composer = require (“composer”)

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()”



– 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

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)

    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

device_width = display.contentWidth --larghezza in pixel dello schermo del tel

device_height = display.contentHeight --altezza in pixel dello schermo del tel

–impostazione sfondo 

local sfondo = display.newImageRect( “sfondonero.png”,device_width,device_height)

sfondo.x= device_width/2

sfondo.y= device_height/2

–richiamo libreria per i widgets 

local widget = require(“widget”)

–funzione che viene richiamata quando il bottone viene premuto quindi quando è nello stato “ended” 

local function handleButtonEvent ( event )

  local phase = event.phase 

  if “ended” == event.phase then 

    print (“Hello World”) 

  end 

end 

  

ty so much 

All your code has to be within the scene structure, you put your code after the return scene! return scene is the last code of your file, there can be nothing below it. try placing your code below: function scene: create (event)  local sceneGroup = self.view

You can’t have code after ‘return scene’. 

EDIT: what he said

i did and im still getting the same error,my code is between the template and here’s the code (ty)

local composer = require( “composer” )

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()”



– Scene event functions


– create()

function scene:create( event )

    local sceneGroup = self.view

    device_width = display.contentWidth --larghezza in pixel dello schermo del tel

device_height = display.contentHeight --altezza in pixel dello schermo del tel

local coomposer = require (“composer”)

–impostazione sfondo 

local sfondo = display.newImageRect( “sfondonero.png”,device_width,device_height)

sfondo.x= device_width/2

sfondo.y= device_height/2

–richiamo libreria per i widgets 

local widget = require(“widget”)

–funzione che viene richiamata quando il bottone viene premuto quindi quando è nello stato “ended” 

local function handleButtonEvent ( event )

  local phase = event.phase 

  if “ended” == event.phase then 

    print (“Hello World”) 

  end 

end 

–creazione bottone numero 1 

local button1 = widget.newButton

{

  left = 35 ,

  top = 400 ,

  width = 22 ,

  height = 54,

  defaultFile = (“Sfondi/icons/1.png”),

  overFile = (“Sfondi/icons/1.png”),

  onEvent = handleButtonEvent

}

–creazione bottone numero 2

local button2 = widget.newButton

{

  left = 120 ,

  top = 400 ,

  width = 22 ,

  height = 54,

  defaultFile = (“Sfondi/icons/2.png”),

  overFile = (“Sfondi/icons/2.png”),

  onEvent = handleButtonEvent

}

–creazione bottone numero 3 

local button3 = widget.newButton

{

  left = 205 ,

  top = 400 ,

  width = 22 ,

  height = 54,

  defaultFile = (“Sfondi/icons/3.png”),

  overFile = (“Sfondi/icons/3.png”),

  onEvent = handleButtonEvent

}

–creazione bottone addizione 

local button_addizione = widget.newButton

{

  left = 279,

  top = 417 ,

  width = 22 ,

  height = 20,

  defaultFile = (“Sfondi/icons/Group 57.png”),

  overFile = (“Sfondi/icons/Group 57.png”),

  onEvent = handleButtonEvent

}

–creazione bottone numero 0

local button0 = widget.newButton

{ left = 120,

  top = 490 ,

  width = 22,

  height = 54,

  defaultFile = (“Sfondi/icons/0.png”),

  overFile = (“Sfondi/icons/0.png”),

  onEvent = handleButtonEvent

}

–creazione bottone punto decimale 

local button_decimale = widget.newButton

{ left = 210,

  top = 523 ,

  width = 11,

  height = 11,

  defaultFile = (“Sfondi/icons/Ellipse 14.png”),

  overFile = (“Sfondi/icons/Ellipse 14.png”),

  onEvent = handleButtonEvent

}

–creazione bottone uguale 

local button_uguale = widget.newButton

  left = 265,

  top = 494,

  width = 50,

  height = 50 ,

  defaultFile = (“Sfondi/icons/Group 55.png”),

  overFile = (“Sfondi/icons/Group 55.png”),

  onEvent = handleButtonEvent

}

– creazione bottone numero 4 

local button4 = widget.newButton

{ left = 35 ,

  top = 330 ,

  width = 22,

  height = 54 ,

  defaultFile = (“Sfondi/icons/4.png”),

  overFile = (“Sfondi/icons/4.png”),

  onEvent = handleButtonEvent

}

– creazione bottone numero 5 

local button5 = widget.newButton

{ left = 120,

  top = 330 ,

 width = 22 ,

 height = 54 ,

 defaultFile = (“Sfondi/icons/5.png”),

 overFile = (“Sfondi/icons/4.png”),

 onEvent = handleButtonEvent

}

–creazione bottone numero 6 

local button6 = widget.newButton

{left = 205,

  top = 330,

  width = 22,

  height = 54,

  defaultFile = (“Sfondi/icons/6.png”),

  overFile = (“Sfondi/icons/6.png”),

  onEvent = handleButtonEvent

}

–creazione bottone sottrazzione 

local button_sottrazione = widget.newButton

{

  left = 277,

  top = 348 ,

  width = 27 ,

  height = 4,

  defaultFile = (“Sfondi/icons/Rectangle -2.png”),

  overFile = (“Sfondi/icons/Rectangle -2.png”),

  onEvent = handleButtonEvent

}

–creazione bottone numero 7 

local button7 = widget.newButton

{ left = 35,

  top = 260,

  width = 22,

  height = 54,

  defaultFile = (“Sfondi/icons/7.png”),

  overFile = (“Sfondi/icons/7.png”),

  onEvent = handleButtonEvent

}

–creazione bottone numero 8

local button8= widget.newButton

{ left = 120,

  top = 260,

  width = 22 ,

  height = 54,

  defaultFile = (“Sfondi/icons/8.png”),

  overFile = (“Sfondi/icons/8.png”),

  onEvent = handleButtonEvent

}

–creazione bottone numero 9

local button9= widget.newButton

{

  left = 205 ,

  top = 260 ,

  width = 22 ,

  height = 54,

  defaultFile = (“Sfondi/icons/9.png”),

  overFile = (“Sfondi/icons/9.png”),

  onEvent = handleButtonEvent

}

– creazione bottone moltiplicazione 

local button_moltiplicazione = widget.newButton

{ left = 278,

  top = 277 ,

  width = 23.38 ,

  height = 23.23,

  defaultFile = (“Sfondi/icons/Group 51.png”),

  overFile = (“Sfondi/icons/Group 51.png”),

  onEvent = handleButtonEvent

}

–creazione bottone cancella 

button_canc = widget.newButton

{ left = 265, 

  top = 207,

  width = 39.51,

  height = 26,

  defaultFile = (“Sfondi/icons/Group 41.png”),

  overFile = (“Sfondi/icons/Group 41.png”),

  onEvent = handleButtonEvent

}

–creazione bottone percentuale 

local button_percentuale = widget.newButton

{ left = 207 ,

  top = 207 ,

  width = 21.96 ,

  height = 24.73 ,

  defaultFile = (“Sfondi/icons/Group 49.png”),

  overFile = (“Sfondi/icons/Group 49.png”),

  onEvent = handleButtonEvent

}

–creazione bottone divisione 

local button_divisione = widget.newButton

{ left = 119 , 

  top = 208 ,

  width = 25 ,

  height = 20 , 

  defaultFile = (“Sfondi/icons/Group 56.png”),

  overFile = (“Sfondi/icons/Group 56.png”),

  onEvent = handleButtonEvent

}

–creazione bottone AC 

local button_ac = widget.newButton

{ left = 35 ,

  top = 206 ,

  width = 26 , 

  height = 28 , 

  defaultFile = (“Sfondi/icons/AC.png”),

  overFile = (“Sfondi/icons/AC.png”),

  onEvent = handleButtonEvent

}

–creazione linea di separazione 

local button_linea = widget.newButton

{ left = -38,

  top = 150 ,

  width = 360 , 

  height = 1 ,

  defaultFile = (“Sfondi/icons/Line 33.png”),

  overFile = (“Sfondi/icons/Line 33.png”),

}

–creazione bottone menu home  (menu 1 ) 

local button_menuhome = widget.newButton

{ left = 105 ,

  top = -55 ,

  width = 27 ,

  height = 22 , 

  defaultFile = (“Sfondi/icons/Group 52.png”),

  overFile = (“Sfondi/icons/Group 52.png”),

  onEvent = handleButtonEvent

}

–creazione button menu 2 

local button_menu2 = widget.newButton

{ left = 205 ,

  top = -57 , 

  width = 26 ,

  height = 26 , 

  defaultFile = (“Sfondi/icons/Group 54.png”),

  overFile = (“Sfondi/icons/Group 54.png”),

  onEvent = handleButtonEvent

}

  

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)

    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

Comment all of your code out and put it back in gradually until you get the error. 

yea but my code works perfectly fine on the main.lua i think there something wrong with the composer when it comes to switch the scene to “home2.lua”

Composer will fail if the scene it is trying to load has a formatting error, and won’t necessarily tell you what that error is.

Get a blank composer scene working, and gradually add your code in. People don’t have time to look through 300 lines of code, and they can’t run it because they don’t have the images.

I tested your code here without the button images and gave no error, are you sure it’s the same error?

yea i did in the main.lua there was just
Local composer = require (“composer”)
composer.gotoScene (“menu2”)

And in the menu2.lua there is just the template you guys sent me and in between it sfondo = display.newImageReact ("Sfondi/icons/sfondonero2) and it still doesnt work :confused:

" L ocal"???

copy all your main and menu2 code again and put it here, but please, before posting, use the <> format icon to make the code better read.

sorry idk what u by <>format, im new to corona amd lua :frowning: btw the menu code is this (main.lua is just local composer = require (“composer”)
composer.gotoScene (“menu2”)

Menu2:
local composer = require( “composer” )

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()”



– Scene event functions


– create()
function scene:create( event )

local sceneGroup = self.view
device_width = display.contentWidth --larghezza in pixel dello schermo del tel
device_height = display.contentHeight --altezza in pixel dello schermo del tel
local coomposer = require (“composer”)
–impostazione sfondo
local sfondo = display.newImageRect( “sfondonero.png”,device_width,device_height)

sfondo.x= device_width/2
sfondo.y= device_height/2

–richiamo libreria per i widgets
local widget = require(“widget”)

–funzione che viene richiamata quando il bottone viene premuto quindi quando è nello stato “ended”

local function handleButtonEvent ( event )
local phase = event.phase
if “ended” == event.phase then
print (“Hello World”)
end
end

–creazione bottone numero 1
local button1 = widget.newButton

{
left = 35 ,
top = 400 ,
width = 22 ,
height = 54,
defaultFile = (“Sfondi/icons/1.png”),
overFile = (“Sfondi/icons/1.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 2
local button2 = widget.newButton

{
left = 120 ,
top = 400 ,
width = 22 ,
height = 54,
defaultFile = (“Sfondi/icons/2.png”),
overFile = (“Sfondi/icons/2.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 3
local button3 = widget.newButton

{
left = 205 ,
top = 400 ,
width = 22 ,
height = 54,
defaultFile = (“Sfondi/icons/3.png”),
overFile = (“Sfondi/icons/3.png”),
onEvent = handleButtonEvent
}

–creazione bottone addizione
local button_addizione = widget.newButton

{
left = 279,
top = 417 ,
width = 22 ,
height = 20,
defaultFile = (“Sfondi/icons/Group 57.png”),
overFile = (“Sfondi/icons/Group 57.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 0
local button0 = widget.newButton

{ left = 120,
top = 490 ,
width = 22,
height = 54,
defaultFile = (“Sfondi/icons/0.png”),
overFile = (“Sfondi/icons/0.png”),
onEvent = handleButtonEvent
}

–creazione bottone punto decimale
local button_decimale = widget.newButton

{ left = 210,
top = 523 ,
width = 11,
height = 11,
defaultFile = (“Sfondi/icons/Ellipse 14.png”),
overFile = (“Sfondi/icons/Ellipse 14.png”),
onEvent = handleButtonEvent
}

–creazione bottone uguale
local button_uguale = widget.newButton

{
left = 265,
top = 494,
width = 50,
height = 50 ,
defaultFile = (“Sfondi/icons/Group 55.png”),
overFile = (“Sfondi/icons/Group 55.png”),
onEvent = handleButtonEvent
}

– creazione bottone numero 4
local button4 = widget.newButton

{ left = 35 ,
top = 330 ,
width = 22,
height = 54 ,
defaultFile = (“Sfondi/icons/4.png”),
overFile = (“Sfondi/icons/4.png”),
onEvent = handleButtonEvent
}

– creazione bottone numero 5
local button5 = widget.newButton

{ left = 120,
top = 330 ,
width = 22 ,
height = 54 ,
defaultFile = (“Sfondi/icons/5.png”),
overFile = (“Sfondi/icons/4.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 6
local button6 = widget.newButton

{left = 205,
top = 330,
width = 22,
height = 54,
defaultFile = (“Sfondi/icons/6.png”),
overFile = (“Sfondi/icons/6.png”),
onEvent = handleButtonEvent
}

–creazione bottone sottrazzione

local button_sottrazione = widget.newButton

{
left = 277,
top = 348 ,
width = 27 ,
height = 4,
defaultFile = (“Sfondi/icons/Rectangle -2.png”),
overFile = (“Sfondi/icons/Rectangle -2.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 7

local button7 = widget.newButton

{ left = 35,
top = 260,
width = 22,
height = 54,
defaultFile = (“Sfondi/icons/7.png”),
overFile = (“Sfondi/icons/7.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 8

local button8= widget.newButton

{ left = 120,
top = 260,
width = 22 ,
height = 54,
defaultFile = (“Sfondi/icons/8.png”),
overFile = (“Sfondi/icons/8.png”),
onEvent = handleButtonEvent
}

–creazione bottone numero 9

local button9= widget.newButton

{
left = 205 ,
top = 260 ,
width = 22 ,
height = 54,
defaultFile = (“Sfondi/icons/9.png”),
overFile = (“Sfondi/icons/9.png”),
onEvent = handleButtonEvent
}

– creazione bottone moltiplicazione

local button_moltiplicazione = widget.newButton

{ left = 278,
top = 277 ,
width = 23.38 ,
height = 23.23,
defaultFile = (“Sfondi/icons/Group 51.png”),
overFile = (“Sfondi/icons/Group 51.png”),
onEvent = handleButtonEvent
}

–creazione bottone cancella
button_canc = widget.newButton

{ left = 265,
top = 207,
width = 39.51,
height = 26,
defaultFile = (“Sfondi/icons/Group 41.png”),
overFile = (“Sfondi/icons/Group 41.png”),
onEvent = handleButtonEvent
}

–creazione bottone percentuale

local button_percentuale = widget.newButton

{ left = 207 ,
top = 207 ,
width = 21.96 ,
height = 24.73 ,
defaultFile = (“Sfondi/icons/Group 49.png”),
overFile = (“Sfondi/icons/Group 49.png”),
onEvent = handleButtonEvent
}

–creazione bottone divisione

local button_divisione = widget.newButton

{ left = 119 ,
top = 208 ,
width = 25 ,
height = 20 ,
defaultFile = (“Sfondi/icons/Group 56.png”),
overFile = (“Sfondi/icons/Group 56.png”),
onEvent = handleButtonEvent
}

–creazione bottone AC

local button_ac = widget.newButton

{ left = 35 ,
top = 206 ,
width = 26 ,
height = 28 ,
defaultFile = (“Sfondi/icons/AC.png”),
overFile = (“Sfondi/icons/AC.png”),
onEvent = handleButtonEvent
}

–creazione linea di separazione

local button_linea = widget.newButton

{ left = -38,
top = 150 ,
width = 360 ,
height = 1 ,
defaultFile = (“Sfondi/icons/Line 33.png”),
overFile = (“Sfondi/icons/Line 33.png”),

}

–creazione bottone menu home (menu 1 )

local button_menuhome = widget.newButton

{ left = 105 ,
top = -55 ,
width = 27 ,
height = 22 ,
defaultFile = (“Sfondi/icons/Group 52.png”),
overFile = (“Sfondi/icons/Group 52.png”),
onEvent = handleButtonEvent
}

–creazione button menu 2

local button_menu2 = widget.newButton

{ left = 205 ,
top = -57 ,
width = 26 ,
height = 26 ,
defaultFile = (“Sfondi/icons/Group 54.png”),
overFile = (“Sfondi/icons/Group 54.png”),
onEvent = handleButtonEvent
}

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)

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

When you type here in the forum, before posting, you have a button with this symbol <> on the top of the text field, select your entered code and click this icon to format your code at the time you click post.

What error message is appearing?

Your code is apparently correct! Are the main.lua and menu2.lua files in the same directory as folders? Is the filename menu2.lua spelled the same as you typed in the code?

first of all tysm and yes main and menu2 are in the same folder, the files name its ‘menu2.lua’ and its spelled correctly in the main :confused:

the error says that im trying to give the ‘namescene’ (in composer.gotoScene (“menu2”) a nil value :confused:

Can you try what I suggested? Get a blank composer template, call it menu2.lua, and see if it works. Then you know it’s your code. 

That error may be a red-herring, as I said if it tries to load a scene and it can’t parse the Lua it will throw an error before it even starts running the code in the scene.

What code editor are you using?

ZeroBrane

i tried and it composer works if on “home2” there aren’t lines of code, but as soon as i try to add a the change scene templete it gives me this error https://gyazo.com/e40f0fdd40248e85d007224237ca7ea6