[Resolved] gotoScene problem

i have a problem with gotoscene. every time i use the function storyboard.gotoScene( whatever ) an error message comes up in the terminal:

May 30 14:46:21 joshua-places-mac-mini.local Corona Simulator[24800] : CGImageCreate: invalid image size: 0 x 0.
May 30 14:46:21 joshua-places-mac-mini.local Corona Simulator[24800] : CGContextDrawImage: invalid context 0x0
May 30 14:46:21 joshua-places-mac-mini.local Corona Simulator[24800] : CGBitmapContextCreateImage: invalid context 0x0
ImageIO: CGImageDestinationAddImage image parameter is nil
ImageIO: CGImageDestinationFinalize image destination does not have enough images
WARNING: Failed to find image(oldscene.jpg)
Runtime error
?:0: attempt to index a nil value
stack traceback:
[C]: ?
?: in function ‘?’
?: in function ‘gotoScene’
/Users/joshuaplace/Desktop/Games/myGame/level1.lua:112: in function
?: in function <?:215>

here is my code:
am i doing something wrong?

[lua]local function collisionListen()
if player.collision then
return
end
local function playerCollision(self, event)
if event.other.myName=“finishLine” then
storyboard.gotoScene(“finish”)
player:removeEventListener(“collision”, player)
end
end
player.collision=playerCollision
player:addEventListener ( “collision”, player )

end
collisionListen()

[import]uid: 147322 topic_id: 26953 reply_id: 326953[/import]

Can you post up a little more code? [import]uid: 84637 topic_id: 26953 reply_id: 109719[/import]

here is my entire scene and finish scene:

as a side note, how do you close your source code highlighting section?
some extras:

-the problem is not with “finish.lua” because i tried instantly going to that scene in “main.lua” and it worked

-the collision sensor is firing off (i made it print something and not go to the scene to test)
[lua]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

function scene:createScene( event )
local group = self.view
end

function scene:enterScene( event )
local group = self.view

game=display.newGroup() --main group (for later on camera movement)

local movieclip=require (“movieclip”)
local ui = require( “ui” )
local physics = require “physics”
physics.start()
physics.setGravity( 0,9.8 )

local height=display.contentHeight
local width=display.contentWidth
local middleY = display.contentHeight/2
local middleX = display.contentWidth/2

local background=display.newRect( 90, 90, display.contentWidth, display.contentHeight+156 )
background.x, background.y = middleX, middleY
background:setFillColor( 120, 120, 120)
game:insert(background)

local ground=display.newRect(0, 0, 1024, 10)
ground.x, ground.y=512, 710
physics.addBody( ground, “static”, { bounce=0.0, friction=0.5 } )
ground:setFillColor(0, 0, 0)
game:insert(ground)

local player=display.newCircle(0, 0, 30)
player.x, player.y=75, 384
physics.addBody(player, {bounce=0.1, density=0.1, radius=30})
player:setFillColor(255, 255, 0)
player.isSleepingAllowed=false
player:setLinearVelocity( 255, 0)
player.name=“player”
game:insert(player)

local finish=display.newRect(0,0,50,50)
finish.x, finish.y=800,650
physics.addBody( finish, “static”, {})
finish.name=“finishLine”

local function collisionListen()
if player.collision then
return
end
local function playerCollision(self, event)
if event.other.name==“finishLine” then --sorry, that should have had two equal signs
storyboard.gotoScene(“finish”)
player:removeEventListener(“collision”, player)
end
end
player.collision=playerCollision
player:addEventListener ( “collision”, player )

end
collisionListen()

end

function scene:exitScene( event )
local group = self.view
end

function scene:destroyScene( event )
local group = self.view
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
return scene

–finish.lua: (very simple scene, only for confirming if it went to the scene)

local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

function scene:createScene( event )
local group = self.view
end

function scene:enterScene( event )
local group = self.view

local finishText=display.newText(“You Finished!”, 0, 0, native.systemFont, 75 )
finishText.x, finishText.y=512, 384
finishText:setTextColor(255, 255, 255)

end

function scene:exitScene( event )
local group = self.view
end

function scene:destroyScene( event )
local group = self.view
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
return scene
[import]uid: 147322 topic_id: 26953 reply_id: 109730[/import]

Can somebody help me please?

It also does not work if I put the collision listener in the finish object, instead of the player. [import]uid: 147322 topic_id: 26953 reply_id: 110272[/import]

Can’t help you with the physics bit, and the error message sounds like something is definitely wrong in the storyboard code. All I can really offer is a few tips:

  1. Move all of your includes to the beginning of the file. I’m not sure if it does anything “bad” to have them in enterScene() but it certainly couldn’t hurt to keep them at the top.

  2. I would suggest pre-declaring “game” at the top of your code instead of leaving it floating

 local game

That way it’s local but can be seen by everything in the lua file.

  1. When posting here you encapsulate. So start your code with < code > (minus the spaces) and end with < / code > (minus the spaces) [import]uid: 41884 topic_id: 26953 reply_id: 110281[/import]

You must create at least 1 display object and insert it into “group” during the createScene event.

This may have been fixed in a later daily build, but just do this:

in createScene()

  
local background = display.newRect(0,0,display.contentWidth, display.contentHeight)  
group:insert(background)  
  

and your error should magically go away. [import]uid: 19626 topic_id: 26953 reply_id: 110288[/import]

@richard9:
Thank you, that was most beneficial. :slight_smile:

@robmiracle:
Thank you, that was most beneficial. :slight_smile:

binc [import]uid: 147322 topic_id: 26953 reply_id: 110504[/import]