I know this doesn’t answer your question but I’d also highly suggest seeding your random call. Take a look at math.randomseed() which will give you more random numbers. Also make sure that the last item in your array doesn’t have a comma at the end (t = {1, 2, 3,}; is not correct while t = {1, 2, 3}; is). Not sure that would cause that error but it definitely isn’t correct afaik
The problem is in game.lua
Clearly, somewhere in that file you have a statement including this text ’ .contentBounds’, That line is the problem.
- OR -
You have a bug in the code that is being found as soon as the file (game.lua) is loaded. (See my comment from 30 MAY further down in this thread.)
Find that line in game.lua and you’ll be well on your way to resolving this.
10$ says you’ve got a typo, or a scope issue and are trying to get the bounds of a nil variable.
Question: Did you grep your game for the word ‘contentBounds’? In the future do this and you should be better equipped to find the issue.
If you’re an OS X user, invest in a grep tool or use the command line.
If you’re on Windows I highly suggest ‘Agent Ransack’.
The error points to a situation in composer.gotoScene() where we are trying to save and hide the current scene. We attempt to get the contentBounds of the currentScene. We are not testing for the scene to be nil before trying to fetch it’s bounding box. We probably should harden that.
Some how in your code you’ve managed to get the current scene to be nil. It’s like you’ve managed the remove the scene you are currently in. I would look at your code and make sure you’re not trying to remove the current scene.
Rob
I’ve seen this happen when the incoming scene has a syntax error that is found when the scene file is first loaded.
The easiest way I’ve found to ‘dig into’ these errors is to use a trick.
Require the scene file and see what errors pop out.
In main.lua do this:
require "game"
If it produces errors, fix the errors if not, remove this line and move on to the next step in debugging.
I did this
local composer = require( "composer" ) composer.gotoScene("start") require "game"
and no errors showed
That’s not what I suggested.
Just put the require “game” at the top of main.lua before any calls to composer. If it doesn’t print any errors, you’ve got some other issue.
quick drive-by: look at the show event, not checking phase, will add two listeners, will call gotoScene twice
Good catch Dave. His code is also calling removeScene twice too.
Rob
How do I check the phase ?
I don’t see where I called it twice and I reviewed it multiple times
Please, try and do your own research before asking such basic questions. The docs are there for a reason!
There is also a guide you should read as well: https://docs.coronalabs.com/guide/system/composer/index.html
There is a diagram that helps explain how Composer’s events flow.
Rob
I have this code and the problem is solved :
function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") end composer.removeScene( "restart" ) end scene:addEventListener( "show" )
Thanks everyone for the help .
That doesn’t seem right. You’re removing twice.
Probably better to do this:
function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") composer.removeScene( "restart" ) -- MOVE IT TO DID end end scene:addEventListener( "show" )
Should I do it to both scenes ?
When I do that I get the former error
Whether I do this code or the code I fount I’m still getting the error
You need to post your updated code. We can’t guess at what you’ve actually done. And you need to post the exact error again as something might be different there since your line numbers are likely different.
Rob
This is what I have and I’m not getting any errors :
restart.lua:
function scene:show(event) local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") end composer.removeScene( "game" ) Runtime:addEventListener("touch", touchScreen) end scene:addEventListener( "show" )
game.lua:
function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") end end scene:addEventListener( "show" )