Test file fail!

Hello. I’m conducting an experiment for my app . I made a different file to test switching scenes on collision . When the collision happens in my test file the scene does not switch . However I do  not have any errors pooping up . Here is my main.lua code :

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local physics = require( "physics" ) physics.start() physics.setGravity(0, 15) -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 ground.myName = "ground" physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) local crate = display.newImageRect( "crate.png", 90, 90 ) crate.x = 60 crate.y = 20 crate.rotation = 0 physics.addBody( crate, "dynamic" , { friction=0.5, bounce=0.3 } ) local function onCollision( self, event ) local other = event.other if( event.phase == "began" and self.isCrate and other.isGround ) then timer.performWithDelay( 30, function() composer.openScene( "restart.lua" ) end ) self:removeEventListener( "collision") end return true end crate.collision = onCollision crate:addEventListener( "collision" )

here is my restart.lua code :

local composer = require( "composer" ) local ground = display.newImage( "ground.png" ) ground.x = 200

Why is the scene not switching and what corrections do I need to make.

Thank you.

Your restart.lua isn’t a complete scene file. You cannot go to it.

Then in your onCollision function, I would print out the values of the things you are testing and make sure you’re getting the values  you are expecting.  These prints will go to your console log, which you should be checking for errors beyond what “pops up”.

If you need to know more about debugging, please read this guide: http://docs.coronalabs.com/guide/basics/debugging/index.html

how do I make my restart.lua a full scene ? That’s all I want to ask.

Thank you.

In just about every tutorial, guide and documentation we provide a starting template for you to use. For instance:

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

All of the parts in there are required.  You have to have the few lines at the top that requires composer, creates a new scene and at the end, you have to support four functions and define their event listeners and then finally “return scene”.

Rob

Your restart.lua isn’t a complete scene file. You cannot go to it.

Then in your onCollision function, I would print out the values of the things you are testing and make sure you’re getting the values  you are expecting.  These prints will go to your console log, which you should be checking for errors beyond what “pops up”.

If you need to know more about debugging, please read this guide: http://docs.coronalabs.com/guide/basics/debugging/index.html

how do I make my restart.lua a full scene ? That’s all I want to ask.

Thank you.

In just about every tutorial, guide and documentation we provide a starting template for you to use. For instance:

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

All of the parts in there are required.  You have to have the few lines at the top that requires composer, creates a new scene and at the end, you have to support four functions and define their event listeners and then finally “return scene”.

Rob