I'm nearly there !

As some of you may know I am doing the switch scene on collision in my app .I’m am nearly there with the help of a few people . Now I just have one error blocking my way .I will show you the error and my code .

Error:

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: 05DBAC98
Runtime error
bad argument #1 to ‘find’ (string expected, got table)
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\test bench\main.lua:34: in funct
ion ‘_listener’
        ?: in function <?:141>
        ?: in function <?:221>

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" ground.isGround = true 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" crate.isCrate = true 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 )

What is my error what corrections do I need .

Thank you.

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.

Also, as a general pointer, pay close attention to the error messages you get in the console, and you’ll be able to troubleshoot these sorts of problems yourself, faster than it takes to wait for a response on the forum. In this particular case, the error message you got:

Runtime error bad argument #1 to 'find' (string expected, got table) stack traceback: [C]: in function 'error' ?: in function 'gotoScene' c:\users\true\documents\corona projects\test bench\main.lua:34: in funct ion '\_listener' ?: in function \<?:141\> ?: in function \<?:221\>

very clearly states that Corona encountered a runtime error in line 34 of main.lua, in the function “gotoScene” - and that it was expecting a string but got a table. Since you were passing a table into your gotoScene call instead of a string (which is what composer.gotoScene requires as its first argument), you could have relatively easily identified the problem. This is a skill that gets better over time, so don’t worry if you have a hard time deciphering the error messages at first - but it’s an invaluable skill that will save you lots of time and headaches down the line. Keep it up, and you’ll be fixing these errors in your sleep before you know it!

Thank you so much for your help it switches scene but another error pops up.

I’ll try to decipher it but if I don’t understand it do I post it to the forums?

Hi true,

I would never discourage you from using the forums if you’re stuck on a problem and can’t work it out on your own - that’s what the forums are for, after all! :slight_smile:

But debugging is a good skill to learn, and if you get good enough at it that you don’t need the forums, you’ll be able to get things done a lot faster (for example, it took me almost a full day to reply to this message!).

So absolutely, keep using the forums - but be sure to give it a good effort on your own first, as that will help you become a better debugger (and there’s nothing quite like the satisfaction of identifying and fixing a problem on your own!)

Good luck,

Jason

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.

Also, as a general pointer, pay close attention to the error messages you get in the console, and you’ll be able to troubleshoot these sorts of problems yourself, faster than it takes to wait for a response on the forum. In this particular case, the error message you got:

Runtime error bad argument #1 to 'find' (string expected, got table) stack traceback: [C]: in function 'error' ?: in function 'gotoScene' c:\users\true\documents\corona projects\test bench\main.lua:34: in funct ion '\_listener' ?: in function \<?:141\> ?: in function \<?:221\>

very clearly states that Corona encountered a runtime error in line 34 of main.lua, in the function “gotoScene” - and that it was expecting a string but got a table. Since you were passing a table into your gotoScene call instead of a string (which is what composer.gotoScene requires as its first argument), you could have relatively easily identified the problem. This is a skill that gets better over time, so don’t worry if you have a hard time deciphering the error messages at first - but it’s an invaluable skill that will save you lots of time and headaches down the line. Keep it up, and you’ll be fixing these errors in your sleep before you know it!

Thank you so much for your help it switches scene but another error pops up.

I’ll try to decipher it but if I don’t understand it do I post it to the forums?

Hi true,

I would never discourage you from using the forums if you’re stuck on a problem and can’t work it out on your own - that’s what the forums are for, after all! :slight_smile:

But debugging is a good skill to learn, and if you get good enough at it that you don’t need the forums, you’ll be able to get things done a lot faster (for example, it took me almost a full day to reply to this message!).

So absolutely, keep using the forums - but be sure to give it a good effort on your own first, as that will help you become a better debugger (and there’s nothing quite like the satisfaction of identifying and fixing a problem on your own!)

Good luck,

Jason