[Resolved] Help: gotoScene produces Error

I’m trying to write a simple app, and although I have used Storyboard before I dont know why this app doesnt want to work. Previous apps still work so the problem is most certainly with the code. I get the following errors when I run, the strangest being the first warning since I never declared any oldscene.jpg:

Warning: Failed to find image(oldscene.jpg)
Runtime error
?:0 attempt to index a nil value
stack traceback:
[C]:?
?: in function ‘?’
?: in function ‘gotoScene’

[code]


– scenetemplate.lua


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



– NOTE:

– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.



– BEGINNING OF YOUR IMPLEMENTATION

– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view

local pageText = display.newText (“Hello World”, 0, 0, native.systemFont, 28)
pageText.x = display.contentWidth * 0.5
pageText.y = display.contentHeight - (display.contentHeight*0.95)

local object = display.newImage( “fdmnov11.png” )
object.id = “ball object”
object.x = display.contentCenterX
object.y = display.contentCenterY

local function onObjectTouch( event )
if event.phase == “began” then
print( "Touch event began on " )
storyboard.gotoScene( “articles”)
end
return true
end
object:addEventListener( “touch”, onObjectTouch )

– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.


end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view


– INSERT code here (e.g. start timers, load audio, start listeners, etc.)


end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view


– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)


end
– Call*ed prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view


– INSERT code here (e.g. remove listeners, widgets, save state, etc.)


end

– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene
[/code] [import]uid: 76592 topic_id: 30538 reply_id: 330538[/import]

Are you getting the error truly when you just run or is it when you fire off the onObjectTouch function? If it’s immediately when you run then this file wouldn’t be the culprit(error should actually tell you which file, btw). do you have a gotoscene in your main.lua? [import]uid: 147305 topic_id: 30538 reply_id: 122337[/import]

When the gotoScene runs everything before that works perfectly. I tried wrapping it in a widget button and ui button same error. I do have a gotoScene in my main.lua. And yes the error does tell me that this file is the culprit :slight_smile: Thanks [import]uid: 76592 topic_id: 30538 reply_id: 122340[/import]

The error could be in articles, try requiring it just before the gotoScene and you will get a better error message.

Obviously remove the require once you have found the error.

Dave [import]uid: 117617 topic_id: 30538 reply_id: 122399[/import]

articles.lua is the exact same as this file. I tried adding require (“articles”) but am still getting the same error :frowning: [import]uid: 76592 topic_id: 30538 reply_id: 122409[/import]

What version of Corona are you running?

This error used to appear in some older versions (and may still do) when you DO NOT create a display object in the createScene() phase and stick it into the view (group:insert(object)).

In your code above you are not inserting pageText and object into “group”

group:insert(pageText)
group:insert(object)

And the scene you are calling has to do the same thing.

At least that bug was happening back in the 700’s. If I remember correctly, Storyboard was trying to take a snapshot of the scene it was moving on to the screen for efficiency, and it couldn’t take a snapshot of the empty group. But this was leading to delays in changing scenes so I thought they dropped that. This is why I think you may have an older version. 894 is the latest public (and daily) build and is what you should be using unless you need to support OS’s older than 4.3 in which case this issue is going to exist in 704.

It’s an easy fix. Insert something into group.
[import]uid: 19626 topic_id: 30538 reply_id: 122443[/import]

That was it!! Thanks! [import]uid: 76592 topic_id: 30538 reply_id: 122451[/import]

Are you getting the error truly when you just run or is it when you fire off the onObjectTouch function? If it’s immediately when you run then this file wouldn’t be the culprit(error should actually tell you which file, btw). do you have a gotoscene in your main.lua? [import]uid: 147305 topic_id: 30538 reply_id: 122337[/import]

When the gotoScene runs everything before that works perfectly. I tried wrapping it in a widget button and ui button same error. I do have a gotoScene in my main.lua. And yes the error does tell me that this file is the culprit :slight_smile: Thanks [import]uid: 76592 topic_id: 30538 reply_id: 122340[/import]

The error could be in articles, try requiring it just before the gotoScene and you will get a better error message.

Obviously remove the require once you have found the error.

Dave [import]uid: 117617 topic_id: 30538 reply_id: 122399[/import]

articles.lua is the exact same as this file. I tried adding require (“articles”) but am still getting the same error :frowning: [import]uid: 76592 topic_id: 30538 reply_id: 122409[/import]

What version of Corona are you running?

This error used to appear in some older versions (and may still do) when you DO NOT create a display object in the createScene() phase and stick it into the view (group:insert(object)).

In your code above you are not inserting pageText and object into “group”

group:insert(pageText)
group:insert(object)

And the scene you are calling has to do the same thing.

At least that bug was happening back in the 700’s. If I remember correctly, Storyboard was trying to take a snapshot of the scene it was moving on to the screen for efficiency, and it couldn’t take a snapshot of the empty group. But this was leading to delays in changing scenes so I thought they dropped that. This is why I think you may have an older version. 894 is the latest public (and daily) build and is what you should be using unless you need to support OS’s older than 4.3 in which case this issue is going to exist in 704.

It’s an easy fix. Insert something into group.
[import]uid: 19626 topic_id: 30538 reply_id: 122443[/import]

That was it!! Thanks! [import]uid: 76592 topic_id: 30538 reply_id: 122451[/import]