StoryBoard API Problems

I’m experimenting with StoryBoard API, and I ran into a problem. When going from my splash.lua to my game.lua, an error occurs.

Also, do my objects have to be global so they can be removed in destroyScene?

Error:

Windows simulator build date: Dec 9 2011 @ 14:01:29  
Copyright (C) 2009-2011 A n s c a , I n c .  
 Version: 2.0.0  
 Build: 2011.704  
WARNING: Failed to find image(oldscene.jpg)  
Runtime error  
 ?:0: attempt to index a nil value  
stack traceback:  
 [C]: ?  
 ?: in function '?'  
 ?: in function 'gotoScene'  
 ...kyle\documents\my code\corona\placeholder\splash.lua:13: in function  
'\_listener'  
 ?: in function <?:514>  
 ?: in function <?:215>  

Code:
[lua]display.setStatusBar( display.HiddenStatusBar )
local storyboard = require “storyboard”
local scene = storyboard.newScene()

function scene:createScene(event)
local group = self.view
local background = display.newImage(“visuals/splash_background.png”, 0, 0)
end

function scene:enterScene(event)
local group = self.view
local function changeScene()
storyboard.gotoScene(“game”, “slideLeft”, 500)
end
timer.performWithDelay(3000, changeScene)
end

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

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

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)
return scene[/lua] [import]uid: 103624 topic_id: 18957 reply_id: 318957[/import]

Anyone know? [import]uid: 103624 topic_id: 18957 reply_id: 73090[/import]

? [import]uid: 103624 topic_id: 18957 reply_id: 73242[/import]

Read your error message:

WARNING: Failed to find image(oldscene.jpg)

[import]uid: 19626 topic_id: 18957 reply_id: 73247[/import]

Not at all helpful.

I had this problem as well. I got this until I set a background image on the scene’s view although there may be another root cause. i.e.:

local sceneGroup = self.view
image=display.newImage(“some image”)
sceneGroup:insert(image) [import]uid: 107141 topic_id: 18957 reply_id: 73314[/import]

robmiracle is very active in the forum, and very helpful…
His reply was the first thing that came to my mind as well…

with that being said, please reproduce the error in code that you can FULLY release in the forums and I would be more than happy to help you debug. Only pieces of code sometimes just isn’t enough. [import]uid: 21331 topic_id: 18957 reply_id: 73321[/import]

I have also been able to reproduce this same error. If you have nothing in your createScene function, like as follows:

function scene:createScene( event )  
 local screenGroup = self.view  
 screenGroup.y = 44  
 print( "\n2: createScene event" )  
end  

you will get the same error as mentioned.

@lKinx:
To resolve your issue you MUST insert your background image into “group” as follows:

function scene:createScene(event) local group = self.view local background = display.newImage("visuals/splash\_background.png", 0, 0) group:insert( background ) end [import]uid: 71201 topic_id: 18957 reply_id: 73328[/import]

Thanks! I probably should have tried that earlier. The only reason I didn’t do that is because I asked in the past on another thread and I was told I didn’t need to, but it makes sense. Do I only put in display objects, or all (audio, etc)?

Edit: Also, do I have to make my background object global (along with most other variables) so that I can remove it in destroyScene? Or is there an easier way? [import]uid: 103624 topic_id: 18957 reply_id: 73439[/import]

Also, I keep getting this error:

Windows simulator build date: Dec 9 2011 @ 14:01:29 Copyright (C) 2009-2011 A n s c a , I n c . Version: 2.0.0 Build: 2011.704 Runtime error error loading module 'game' from file 'c:\users\kyle\documents\my code\c orona\makin' bank\game.lua': c:\users\kyle\documents\my code\corona\makin' bank\game.lua:77: '(' expe cted near ':' stack traceback: [C]: ? [C]: ? [C]: in function '

For some reason it doesn’t like my collision functions. (Line 77 is the first line in the code below.)

[lua] local function ground:collision(event)
event.other:removeSelf()
end
ground:addEventListener(“collision”, ground)[/lua] [import]uid: 103624 topic_id: 18957 reply_id: 73624[/import]

Well after posting that, guess what… I’ve now encountered the same error using Storyboard with widget items.

It’s funny. I have a game using Storyboard and I don’t have errors. I have another app and this is blowing up all over the place.

I can reproduce it and I think I know the cause.

-- main.lua  
  
local storyboard = require("storyboard")  
  
local function showScreen4()  
 storyboard.gotoScene("tab4")  
end  
  
b = display.newRect(10,10,60,60);  
b:setFillColor(255)  
b:addEventListener("tap", showScreen4)  
  
-- tab4.lua  
  
rmiracle-mbp15:tabBar rmiracle$ vi tab4.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  
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  

This code will create the error. I see the white square generated in main.lua. I click on it and nothing happens. I click on it again (almost like it didn’t have focus) and then I get that error.

If I change tab4 to actually draw something and put it in the group:

  
rmiracle-mbp15:tabBar rmiracle$ vi tab4.lua  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
function scene:createScene( event )  
 local group = self.view  
  
 local x = display.newRect(100,100,100,100)  
 x:setFillColor(255,255,0)  
 group:insert(x)  
end  
  
function scene:enterScene( event )  
 local group = self.view  
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  

Now when I click on the white square the first time, tab4 now draws the yellow box on the screen (doesn’t remove the white square, but in fairness, it’s not in a group. Most Storyboard stuff doesn’t put stuff in a group from main unless its stuff that stays on the screen.

Continuing to click on the white square appears to do nothing, but it may be reloading the scene again.

Now in my project where this is failing horribly, I’m putting stuff in the “group”. This has me baffled. [import]uid: 19626 topic_id: 18957 reply_id: 73645[/import]

So it’s not necessarily my code. For some reason it doesn’t like listeners.

Again, do I only put in display objects into the group, or all objects (audio, etc)? Also, do I have to make my background object global (along with most other variables) so that I can remove it in destroyScene? Or is there an easier way? [import]uid: 103624 topic_id: 18957 reply_id: 73659[/import]

groups are for display objects only. No audio, or other stuff.

As for the background object, if you do a group:insert() on it, it should remove itself when the scene is destroyed. [import]uid: 19626 topic_id: 18957 reply_id: 73664[/import]

@IKinx: Would you mind zipping up your code and submitting a bug with it attached?

http://developer.anscamobile.com/content/bug-submission

I think this may be related to a bug that was submitted earlier today, so the more angles we can look at the (possibly) same issue, the easier it will be to narrow down the source of the problem. [import]uid: 52430 topic_id: 18957 reply_id: 73674[/import]

So as long as I put my display objects into the group, I don’t have to remove them individually in destroyScene?

Basically in destroyScene I should be removing audio, timers, and others things that were paused in exitScene.

And I’ll submit a bug report. [import]uid: 103624 topic_id: 18957 reply_id: 73690[/import]

I am having the oldscene.jpg issue also…simply trying to gotoScene. In my exitScene, I have code to unhook listeners (had to modify the ui.Button with a Kill call to remove the touch event) and then remove the background and button objects from the display list via display.remove(object).

Here’s what happens when I call gotoScene from within my click handler (an anonymous function…but I tried it with a standard function also):

WARNING: Failed to find image(oldscene.jpg)
Runtime error

?:0: attempt to index a nil value

stack traceback:
[C]: ?
?: in function ‘?’

This is my very first attempt to use the storyboard API, and it’s a simple screen with a background and 4 buttons.

Any ideas would be immensely appreciated, because I am stuck and hoped to make great progress this week. :frowning:

-John [import]uid: 29170 topic_id: 18957 reply_id: 75842[/import]

are you putting at least one display object into “group” in each scene?

Its possible there are errors in your scene file too. [import]uid: 19626 topic_id: 18957 reply_id: 75844[/import]

Rob, that was it…thanks so much. I guess my “ready, fire, aim” personality is getting the best of me again. :slight_smile:

-John
[import]uid: 29170 topic_id: 18957 reply_id: 75856[/import]

I’m getting some weird problems with storyboard with loading the same level more than 3 times.

For example if the player dies on level 1 I call storyboard.gotoScene( “reloadscene” ) which uses the storyboard.removeAll() to remove level 1 then it reloads level 1 by calling storyboard.gotoScene( “level1” ).

Everything works perfect until after the third or forth time I reload the scene. Then on some reloads some functions don’t spawn objects, remove objects and transition. It appears that not all of the level is being removed everytime. I get this same issue on the simulator and android device but I don’t receive any error messages.

update: I found the problem it was a bug in my code not storyboard. [import]uid: 38820 topic_id: 18957 reply_id: 78100[/import]

Don’t forget to add all display objects to the group. Even widgets have display objects, this is how you add them.

[lua]group:insert(myWidgetButton.view)[/lua] [import]uid: 45119 topic_id: 18957 reply_id: 78590[/import]

Actually prior to 722, trying to add widgets .view’s to group didn’t work very well. In fact I think Jonathan Beebee instructed us to create the widgets during the storybosard enterScene phase instead of createScene and to not insert them into group. Though you still have to have a display object in group!

But as of 722, the whole widget.view concept went away and now widgets are like any other display object and can be put into group’s correctly.

I’m feeling really good about widgets and storyboard as of 722.
[import]uid: 19626 topic_id: 18957 reply_id: 78594[/import]