Hy guys, I have an error and I don’t know how fix it.
When I try to come back to a sceen, used before, this error appears:
storyboard.lua617:in function ‘saveSceneAndHide’
storyboard.lua1612:in function ‘gotoScene’
Hy guys, I have an error and I don’t know how fix it.
When I try to come back to a sceen, used before, this error appears:
storyboard.lua617:in function ‘saveSceneAndHide’
storyboard.lua1612:in function ‘gotoScene’
Can we see the code around livello1.lua line 400?
Also are you inserting all of your display objects you create in scene:createScene() into the scene’s group?
Rob
Hi rob, yes I insert all objects.
this is the code between line 396 and line 400:
local function gameover()
if collisione_personaggio_var == 1 then
rimozione = 0
storyboard.purgeScene(“start”)
storyboard.gotoScene( “gameover”, { effect = “fade”, time = 300 } )
Last instruction is line.400
Thanks.
Frequently those errors are due to errors in the scene you are going to. You will need to look at gameover.lua and see if you can spot any problems. Is “start” the scene you are currently in?
Storyboard isn’t supported any longer. We recommend converting to Composer.
Currently I’m in “livello_1”, the code works so: “start”-“livello_1”-“gameover”, from scene “gameover” you come back in scene “start”.
I don’t find any error
Looking at the code for Storyboard, this is a condition where there are no display objects having been inserted into the scene. It’s trying to get the contentBounds of the current scene’s group and it’s not finding a value for it. This tells me the group is empty.
Since you’ve not posted any code, I don’t know which template you’re using for scenes, but you should have in scene:createScene() something that looks like:
function scene:createScene( event ) local group = self.view
In the app I took this from, “group” is the display group you are supposed to insert things in too. Sometimes it might be called “screenGroup” or something else. When you create any display objects like say the background for the scene you must insert them:
local background = display.newRect(0, 0, display.contentWidth, display.contentHeight) group:insert( background )
Check to make sure you are inserting things into the scene you are leaving and the scene you are going to.
A little piece of code:
function scene:createScene(event)
local screenGroup = self.view
background = display.newImage(“sfondo.png”)
background.x = 250
background.y = 100
screenGroup:insert(background)
Floor = display.newImage(“Floor.png”)
Floor.x = 220
Floor.y = 515
physics.addBody( Floor, “static”)
screenGroup:insert(Floor)
What about the scene you’re going to?
This is the full code about scene “start.lua”:
local storyboard = require (“storyboard”)
local scene = storyboard.newScene()
function scene:createScene(event)
local group = self.view
local gameMusic = audio.loadStream( “base_ballshot.mp3” )
local background_start = display.newImage(“Menubackground.png”)
background_start.x = display.contentWidth * 0.5
background_start.y = 230
group:insert(background_start)
tasto1 = display.newImage(“tastostart.png”)
tasto1.x = display.contentWidth * 0.5 -180
tasto1.y = 250
group:insert(tasto1)
local gameMusicChannel = audio.play( gameMusic, { loops = -1 } )
end
function start(event)
if event.phase == “began” then
storyboard.purgeScene(“livello1”)
storyboard.gotoScene(“livello1”, “fade”, 400)
end
end
function scene:enterScene(event)
storyboard.purgeScene(“livello1”)
tasto1:addEventListener(“touch”, start)
end
function scene:exitScene(event)
display.remove(background)
display.remove(tasto1)
tasto1:removeEventListener(“touch”, start)
end
function scene:destroyScene(event)
end
scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)
return scene
Please use the blue <> button to open a window to paste your code into. I’m more interested in “gameover.lua”.
I don’t konw what you mean whit <> blu button…sorry.
This is the full code about “gameover.lua”:
local storyboard = require (“storyboard”)
local scene = storyboard.newScene()
– background
function scene:createScene(event)
local group = self.view
sfondo_gameover = display.newImage(“gameover.png”)
sfondo_gameover.x = display.contentWidth * 0.5
sfondo_gameover.y = 230
group:insert(sfondo_gameover)
–tasto1.isVisible = true
end
function start(event)
if event.phase == “began” then
storyboard.purgeScene(“livello1”)
storyboard.purgeScene(“start”)
storyboard.gotoScene(“start”, “fade”, 400)
end
end
function scene:enterScene(event)
storyboard.purgeScene(“livello1”)
sfondo_gameover:addEventListener(“touch”, start)
end
function scene:exitScene(event)
sfondo_gameover:removeEventListener(“touch”, start)
end
function scene:destroyScene(event)
end
scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)
return scene
When you are typing a response here in the forums, right above where you type are buttons to Bold, Italicize, Underline, etc. This is the formatting bar. In the middle is an icon that is a blue <> shape between the photo icon and the speech bubble icon. Click it. Paste your code into the window and click Okay.
This will format your code properly.
It looks like you are inserting your gameover.png into the scene correctly. The only thing would be if that image doesn’t exist.
What version of Corona SDK are you using?
The image exist… I’m using Corona SDK v2016.2830.
Is there another way to change sceene?
Yes. Use Composer. See: https://docs.coronalabs.com/guide/system/composer/index.html
Composer is Storyboard’s newer, better brother or Storyboard 2.0 if that helps you imagine what it is. It is however not code compatible with Storyboard. See the Migration guide.
Rob
Hi Rob, I solved that problem, thanks.
But now I have another error:
gameover.lua:30: attempt to call method ‘addEventListener’ (a nil value).
This is the error, I don’t know how fix it.
Sorry, I forgot to say that this error appear only when I try to go to a scene used before.
What is line 30 of gameover.lua? Can you post the code around it? Normally if we can’t find the function addEventListener, which is what this error is saying it’s because the object doesn’t exist. Perhaps if you’re adding this to an image, that image failed to load for some reason (filename not right?).
Rob
local storyboard = require ("storyboard") local scene = storyboard.newScene() local cambio = 0 -- background function scene:createScene(event) local group = self.view background = display.newImage("Gameover.png") background.x = display.contentWidth \* 0.5 background.y = 230 group:insert(background) end function start(event) if event.phase == "ended" and cambio == 0 then storyboard.gotoScene("start") cambio = 1 end end function scene:enterScene(event) storyboard.purgeScene("start") background:addEventListener("touch", start) end function scene:exitScene(event) background:removeEventListener("touch", start) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene
This all scene ‘gameover’
I suspect you are running into a problem from using Global variables. Your “background” is a global. If your start.lua scene also has a variable called background that is global, when you purge your start scene with: storyboard.purgeScene(“start”) it will remove everything in start scene. If start scene has a global named background, it gets removed and later when you try to leave this scene, it can’t find background to remove it.
Globals are evil and you shouldn’t use them unless you absolutely have to.
People use globals as a way to get around dealing with scope. We have a tutorial that tries to explain scope and how to properly code your app so that you can use local variables instead of globals. https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/
In your case, at the very top you have this line:
-- background
change that to:
local background
That will properly scope your background variable in your module so it can be used inside different functions and not run into problems with globals.
Since I can’t see start.lua, I’m only guessing that this the problem because that’s the only reason I can see why background wouldn’t be a display object at that point in your code.
Yes you right.
But if I put local then Corona Simulator tells me that there is an error whit listener, line 36.
local storyboard = require ("storyboard") local scene = storyboard.newScene() local cambio = 0 function scene:createScene(event) local group = self.view local gameMusic = audio.loadStream( "base\_ballshot.mp3" ) local background\_start = display.newImage("Menubackground.png") background\_start.x = display.contentWidth \* 0.5 background\_start.y = 230 group:insert(background\_start) local tasto1 = display.newImage("tastostart.png") tasto1.x = display.contentWidth \* 0.5 -180 tasto1.y = 250 --local gameMusicChannel = audio.play( gameMusic, { loops = -1 } ) end function start(event) if event.phase == "began" then storyboard.gotoScene("livello1", "fade", 400) storyboard.purgeScene("start") end end function scene:enterScene(event) storyboard.purgeScene("gameover") tasto1:addEventListener("touch", start) end function scene:exitScene(event) tasto1:removeEventListener("touch", start) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene