This error makes no sense !

As said in other threads I am trying to switch scene on contact of crate and ground . I have tried to correct my code and I get this error :

Windows simulator build date: Nov 18 2014 @ 18:35:32

Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
create initialized?     table: 02D68F20

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
create initialized?     table: 09F1E8C0

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
Syntax error
c:\users\true\documents\corona projects\test bench\main.lua:35: ‘)’ expected (to
 close ‘(’ at line 32) near ‘self’

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
Syntax error
c:\users\true\documents\corona projects\test bench\main.lua:35: ‘)’ expected (to
 close ‘(’ at line 32) near ‘self’

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
Syntax error
c:\users\true\documents\corona projects\test bench\main.lua:32: unexpected symbo
l near ‘)’

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
Syntax error
c:\users\true\documents\corona projects\test bench\main.lua:32: ‘}’ expected nea
r ‘)’

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
Syntax error
c:\users\true\documents\corona projects\test bench\main.lua:32: unexpected symbo
l near ‘)’

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
Syntax error
c:\users\true\documents\corona projects\test bench\main.lua:32: unexpected symbo
l near ‘)’

Code main.lua:

----------------------------------------------------------------------------------------- -- -- 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 ) print("create initialized? ", crate ) crate.x = 60; crate.y = 20 crate.rotation = 0 crate.myName = "crate" 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.gotoScene { "restart.lua", "fade", 500 }) end self:removeEventListener( "collision" ) end return true end crate.collision = onCollision crate:addEventListener( "collision" )

What is the problem here?What corrections do I need?

Thank you.

Hi true,

I haven’t had time to dig into your post so I can’t say for sure what’s causing this but I can say that you should update your Corona SDK to the latest public build, or a recent daily. You are using build # 2014.2511, which means you are at least 7 months behind the current SDK, which can definitely cause problems if the code you are working with depends on newer APIs or syntax. Not everybody needs to use the daily builds but you should always make sure you’re on the latest public build. I can try to find a more specific cause later, but a good first step will be to update your SDK. :grinning:

The error is pointing to line 32, and indicates a syntax error.  I believe the “end” statement needs to be inside the performWithDelay call.

timer.performWithDelay( 30, function() composer.gotoScene { "restart.lua", "fade", 500 }; end)

when I put this it doesn’t change scene can you explain why.

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 ) print("create initialized? ", crate ) crate.x = 60; crate.y = 20 crate.rotation = 0 crate.myName = "crate" 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.gotoScene { "restart.lua", "fade", 500 }; end) self:removeEventListener( "collision" ) end return true end crate.collision = onCollision crate:addEventListener( "collision" )

Restart.lua :

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view end -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 group:insert(logo) group:insert(ground) scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )

here is the cmd prompt :

Windows simulator build date: May 27 2015 @ 18:15:50

Copyright © 2009-2015  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2015.2646
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2015.2646
Loading project from:   c:\users\true\documents\corona projects\test bench
Project sandbox folder: C:\Users\True\AppData\Roaming\Corona Labs\Corona Simulat
or\Sandbox\test bench-ED6DFA467C72057C41608B6099A18169\Documents
create initialized?     table: 05DE5C00

What is the problem here what corrections do I need

when I put this it doesn’t change scene on collision can you explain why.

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 ) print("create initialized? ", crate ) crate.x = 60; crate.y = 20 crate.rotation = 0 crate.myName = "crate" 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.gotoScene { "restart.lua", "fade", 500 }; end) self:removeEventListener( "collision" ) end return true end crate.collision = onCollision crate:addEventListener( "collision" )

Restart.lua :

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view end -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 group:insert(logo) group:insert(ground) scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )

here is the cmd prompt :

Windows simulator build date: May 27 2015 @ 18:15:50

Copyright © 2009-2015  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2015.2646
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2015.2646
Loading project from:   c:\users\true\documents\corona projects\test bench
Project sandbox folder: C:\Users\True\AppData\Roaming\Corona Labs\Corona Simulat
or\Sandbox\test bench-ED6DFA467C72057C41608B6099A18169\Documents
create initialized?     table: 05DE5C00

What is the problem here what corrections do I need

Where you have this line:

if( event.phase == "began" and self.isCrate and other.isGround ) then

you need all three conditions to evaluate to true. When you make something like crate or ground, they don’t automatically come with properties like isCrate and isGround. Consequently, self.isCrate and other.isGround will always evaluate to nil. When you first make your crate and ground however, you can add these lines:

crate.isCrate = true ground.isGround = true

Which should make things work.

Alternatively you can check in the collision handler whether  self == crate and event.other == ground

Hi true,

When you are calling composer.gotoScene, you are passing a table in by using {curly brackets} - you should be using (parenthesis) instead, as the “gotoScene” API needs to have string values and/or number values passed into it. So replace this:

timer.performWithDelay( 30, function() composer.gotoScene { "restart.lua", "fade", 500 }; end)

with this:

timer.performWithDelay( 30, function() composer.gotoScene ( "restart.lua", "fade", 500 ); end)

and you should have better luck. In general, you should always use parenthesis when calling a function - if the function requires a table, you can always place the curly brackets inside of the parenthesis, for more uniform code formatting.

Hi true,

I haven’t had time to dig into your post so I can’t say for sure what’s causing this but I can say that you should update your Corona SDK to the latest public build, or a recent daily. You are using build # 2014.2511, which means you are at least 7 months behind the current SDK, which can definitely cause problems if the code you are working with depends on newer APIs or syntax. Not everybody needs to use the daily builds but you should always make sure you’re on the latest public build. I can try to find a more specific cause later, but a good first step will be to update your SDK. :grinning:

The error is pointing to line 32, and indicates a syntax error.  I believe the “end” statement needs to be inside the performWithDelay call.

timer.performWithDelay( 30, function() composer.gotoScene { "restart.lua", "fade", 500 }; end)

when I put this it doesn’t change scene can you explain why.

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 ) print("create initialized? ", crate ) crate.x = 60; crate.y = 20 crate.rotation = 0 crate.myName = "crate" 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.gotoScene { "restart.lua", "fade", 500 }; end) self:removeEventListener( "collision" ) end return true end crate.collision = onCollision crate:addEventListener( "collision" )

Restart.lua :

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view end -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 group:insert(logo) group:insert(ground) scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )

here is the cmd prompt :

Windows simulator build date: May 27 2015 @ 18:15:50

Copyright © 2009-2015  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2015.2646
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2015.2646
Loading project from:   c:\users\true\documents\corona projects\test bench
Project sandbox folder: C:\Users\True\AppData\Roaming\Corona Labs\Corona Simulat
or\Sandbox\test bench-ED6DFA467C72057C41608B6099A18169\Documents
create initialized?     table: 05DE5C00

What is the problem here what corrections do I need

when I put this it doesn’t change scene on collision can you explain why.

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 ) print("create initialized? ", crate ) crate.x = 60; crate.y = 20 crate.rotation = 0 crate.myName = "crate" 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.gotoScene { "restart.lua", "fade", 500 }; end) self:removeEventListener( "collision" ) end return true end crate.collision = onCollision crate:addEventListener( "collision" )

Restart.lua :

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view end -- display ground image local ground = display.newImageRect( "ground.png", 500, 100 ) ground.x = 145; ground.y = 480 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 group:insert(logo) group:insert(ground) scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )

here is the cmd prompt :

Windows simulator build date: May 27 2015 @ 18:15:50

Copyright © 2009-2015  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2015.2646
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2015.2646
Loading project from:   c:\users\true\documents\corona projects\test bench
Project sandbox folder: C:\Users\True\AppData\Roaming\Corona Labs\Corona Simulat
or\Sandbox\test bench-ED6DFA467C72057C41608B6099A18169\Documents
create initialized?     table: 05DE5C00

What is the problem here what corrections do I need

Where you have this line:

if( event.phase == "began" and self.isCrate and other.isGround ) then

you need all three conditions to evaluate to true. When you make something like crate or ground, they don’t automatically come with properties like isCrate and isGround. Consequently, self.isCrate and other.isGround will always evaluate to nil. When you first make your crate and ground however, you can add these lines:

crate.isCrate = true ground.isGround = true

Which should make things work.

Alternatively you can check in the collision handler whether  self == crate and event.other == ground

Hi true,

When you are calling composer.gotoScene, you are passing a table in by using {curly brackets} - you should be using (parenthesis) instead, as the “gotoScene” API needs to have string values and/or number values passed into it. So replace this:

timer.performWithDelay( 30, function() composer.gotoScene { "restart.lua", "fade", 500 }; end)

with this:

timer.performWithDelay( 30, function() composer.gotoScene ( "restart.lua", "fade", 500 ); end)

and you should have better luck. In general, you should always use parenthesis when calling a function - if the function requires a table, you can always place the curly brackets inside of the parenthesis, for more uniform code formatting.