Noob Question about Storyboard

I’m attempting a basic scene change.  I’ve modified the Castle Demo and inserted it into a scene called “world”, based on Storyboard demo.  Within the “world” scene, I have a listener that calls a scene change to one called “battle”.  The “battle” scene seems to load (the debug says so at least) but I can’t seem to get the map to display.  I should also note that before my “battle” scene loads, my sprites disappear and the original map, “world”, is still displayed.  I am doing a mte.cleanup() in my destroyscene() method as well… 

Any advise appreciated :wink:

From “world”

local function handleAction(event) if event.phase == "ended" or event.phase == "cancelled" then -- displayWords(cde.myText) storyboard.gotoScene("battle", {effect = "fade", time = 1000}) end end

From “battle”

-- includes and etc above function scene:willEnterScene(event) local group = self.view --LOAD MAP ------------------------------------------------------------ mte.toggleWorldWrapX(true) mte.toggleWorldWrapY(true) mte.loadTileSet("dungeon3DMap", "tilesets/dungeon3DMap.png") mte.loadTileSet("innerFlat", "tilesets/innerFlat.png") mte.loadTileSet("castle3DMap", "tilesets/castle3DMap.png") mte.loadTileSet("townFlat", "tilesets/townFlat.png") mte.loadMap("map/battle.json") -- mte.goto({ locX = 10, locY = 10, blockScaleX = 64, blockScaleY = 64}) --CREATE PLAYER SPRITE ---------------- -- -- Don't think I need all this if it's already setup in world in myData / cde. -- local setup = { kind = "sprite", layer = mte.getSpriteLayer(1), locX = 10, locY = 10, levelWidth = 32, levelHeight = 32, solid = true } mte.addSprite(cde.player, setup) local locX, locY locX, locY = 34, 33 mte.goto({ locX = locX, locY = locY, blockScaleX = 32, blockScaleY = 32}) group:insert(mte.getMapObj()) -- This should at least display the map? mte.update() end local function gameLoop( event ) mte.debug() mte.update() end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) Runtime:addEventListener("enterFrame", gameLoop) end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", 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 )

Two thoughts off the top of my head; first, calling addSprite before goto will cause strange behavior. You should call your goto and then load your sprite.

Second, calling the scene transition in an event can interrupt the engine in less-than-ideal ways and cause strange behavior, simply because you cannot guarantee that it will be triggered after all operations are finished. I suggest using your event to set a flag, and then checking that flag at the end of your enterFrame event and initiating the scene change from there. This guarantees that no other engine operations are taking place when the scene change begins. For example, the end of RotateConstrainStoryboard’s enterFrame reads as follows:

--UPDATE OR GOTO NEW MAP if not changeMap then mte.debug() mte.update() else storyboard.gotoScene("scene", {effect = "fade", time = 1000}) end

Thanks for the insight Dyson.

I actually do get a weird error when I try to addsprite before goto… even weirder when I “goto” before addsprite:

“Attempt to index field ‘?’ (a nil value)”

I’ve double checked the params are proper types and are set.  Well I’ve commented it out.  My map isn’t very big at 30x20.

Beyond the goto call, I’ve updated my loop to check a boolean to run the update / debug or to change scene.  Same results.  Maybe mte doesn’t like to be unloaded then loaded it again in another scene?  There are a few other things I can try.  This has been a good exercise in learning the essential steps in map display.

Ah you know what?  My map is out of sorts.  I load the original CastleDemo.json and it works fine with my code.  Maybe my coord references for goto are out of scope or something?  I have my sprite layer defined and with appropriate layer properties.  The plot thickens  :lol:

Well, in the code snippet above your goto is set to locX = 34, locY = 33, however you said your map is only 30x20 tiles. In this case 34,33 does not exist!

Dyson - this makes sense!  I’m still running into “Attempt to index field ‘?’ (a nil value)” when changing X/Y to 0, 0.  I also tried resizing map to 100x100.  Almost stumped but there are two more options to explore :confused:

If it’s helpful, I put my map file up here (it’s nothing special):

http://s000.tinyupload.com/index.php?file_id=97191485384744662945

Technically 0,0 doesn’t exist either (maps start art 1,1), but that wouldn’t cause an error. 

I see that you’re adding the runtime listener for enterFrame in “function scene:enterScene(event)”, but you are not removing the event listener in exitScene. Are you removing the enterFrame event listener from your world map before trying to load battle? For example:

function scene:exitScene( event ) local group = self.view ----------------------------------------------------------------------------- -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) ----------------------------------------------------------------------------- Runtime:removeEventListener("enterFrame", gameLoop) end

Ok, I get it.  Updated and added the remove listener.  The thing is, I can load “map/CastleDemo.json” and the battle scene loads just fine.  I load “map/battle.json”, and it bombs.  I assume my map is causing this problem somehow.  After looking closer, I didn’t have spacing and margin set correctly but otherwise, I can’t seem to find the culprit.  

Thanks for all the help though Dyson.

How peculiar! If you’d like to email your project to me I’ll have a look at it. 

At the top of your “function scene:willEnterScene(event)” in world.lua you need to declare “local group = self.view”. At the end of the same function you need to add the MTE map object to the view with “group:insert(mte.getMapObj())”. This will allow storyboard to unload the map object when the scene changes.

function scene:willEnterScene(event) local group = self.view --your code group:insert(mte.getMapObj()) end

You were seeing “Attempt to index field ‘?’ (a nil value)” because battle.json requires a tileset you were not loading in battle.lua. You should really pay attention to MTE’s printout statements!

WARNING: Failed to find image(dungeonFlat.png) 2013-08-30 20:29:35.480 Corona Simulator[2453:707] Searching for tileset dungeonFlat.png... 2013-08-30 20:29:35.480 Corona Simulator[2453:707] Checking Resource Directory... 2013-08-30 20:29:35.480 Corona Simulator[2453:707] WARNING: Failed to find image(dungeonFlat.png) 2013-08-30 20:29:35.480 Corona Simulator[2453:707] Checking battle.json folder... 2013-08-30 20:29:35.481 Corona Simulator[2453:707] WARNING: Failed to find image(battle.json/dungeonFlat.png) 2013-08-30 20:29:35.481 Corona Simulator[2453:707] Checking battle folder... 2013-08-30 20:29:35.481 Corona Simulator[2453:707] WARNING: Failed to find image(battle/dungeonFlat.png) 2013-08-30 20:29:35.481 Corona Simulator[2453:707] Checking dungeonFlat.png folder... 2013-08-30 20:29:35.482 Corona Simulator[2453:707] WARNING: Failed to find image(dungeonFlat.png/dungeonFlat.png) 2013-08-30 20:29:35.482 Corona Simulator[2453:707] Checking dungeonFlat folder... 2013-08-30 20:29:35.482 Corona Simulator[2453:707] WARNING: Failed to find image(dungeonFlat/dungeonFlat.png) 2013-08-30 20:29:35.482 Corona Simulator[2453:707] Could not find dungeonFlat.png 2013-08-30 20:29:35.482 Corona Simulator[2453:707] Use mte.getTilesetNames() and mte.loadTileset(name) to load tilesets programmatically.

Usually when the failsafe searches for the image file, something’s wrong somewhere. Anyway, load dungeonFlat.png and everything works fine… but not quite. Is battle.json missing a tileset? It contains tile ID’s above the highest ID in the dungeonFlat tileset.

me_1023.jpg

I see this is a typical noob mistake.  Oh the embarrassment!  The error console doesn’t show up in OSX by default and seems I have to run the simulator from the command line in order to see it.  It’s interesting that in Windows, the console runs by default.  

At the top of your “function scene:willEnterScene(event)” in world.lua you need to declare “local group = self.view”. At the end of the same function you need to add the MTE map object to the view with “group:insert(mte.getMapObj())”. This will allow storyboard to unload the map object when the scene changes.

Point noted.  I would assume memory because an issue otherwise?

You’ve gone beyond the call of duty and I appreciate that.  Thank you!

Two thoughts off the top of my head; first, calling addSprite before goto will cause strange behavior. You should call your goto and then load your sprite.

Second, calling the scene transition in an event can interrupt the engine in less-than-ideal ways and cause strange behavior, simply because you cannot guarantee that it will be triggered after all operations are finished. I suggest using your event to set a flag, and then checking that flag at the end of your enterFrame event and initiating the scene change from there. This guarantees that no other engine operations are taking place when the scene change begins. For example, the end of RotateConstrainStoryboard’s enterFrame reads as follows:

--UPDATE OR GOTO NEW MAP if not changeMap then mte.debug() mte.update() else storyboard.gotoScene("scene", {effect = "fade", time = 1000}) end

Thanks for the insight Dyson.

I actually do get a weird error when I try to addsprite before goto… even weirder when I “goto” before addsprite:

“Attempt to index field ‘?’ (a nil value)”

I’ve double checked the params are proper types and are set.  Well I’ve commented it out.  My map isn’t very big at 30x20.

Beyond the goto call, I’ve updated my loop to check a boolean to run the update / debug or to change scene.  Same results.  Maybe mte doesn’t like to be unloaded then loaded it again in another scene?  There are a few other things I can try.  This has been a good exercise in learning the essential steps in map display.

Ah you know what?  My map is out of sorts.  I load the original CastleDemo.json and it works fine with my code.  Maybe my coord references for goto are out of scope or something?  I have my sprite layer defined and with appropriate layer properties.  The plot thickens  :lol:

Well, in the code snippet above your goto is set to locX = 34, locY = 33, however you said your map is only 30x20 tiles. In this case 34,33 does not exist!

Dyson - this makes sense!  I’m still running into “Attempt to index field ‘?’ (a nil value)” when changing X/Y to 0, 0.  I also tried resizing map to 100x100.  Almost stumped but there are two more options to explore :confused:

If it’s helpful, I put my map file up here (it’s nothing special):

http://s000.tinyupload.com/index.php?file_id=97191485384744662945

Technically 0,0 doesn’t exist either (maps start art 1,1), but that wouldn’t cause an error. 

I see that you’re adding the runtime listener for enterFrame in “function scene:enterScene(event)”, but you are not removing the event listener in exitScene. Are you removing the enterFrame event listener from your world map before trying to load battle? For example:

function scene:exitScene( event ) local group = self.view ----------------------------------------------------------------------------- -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) ----------------------------------------------------------------------------- Runtime:removeEventListener("enterFrame", gameLoop) end

Ok, I get it.  Updated and added the remove listener.  The thing is, I can load “map/CastleDemo.json” and the battle scene loads just fine.  I load “map/battle.json”, and it bombs.  I assume my map is causing this problem somehow.  After looking closer, I didn’t have spacing and margin set correctly but otherwise, I can’t seem to find the culprit.  

Thanks for all the help though Dyson.

How peculiar! If you’d like to email your project to me I’ll have a look at it. 

At the top of your “function scene:willEnterScene(event)” in world.lua you need to declare “local group = self.view”. At the end of the same function you need to add the MTE map object to the view with “group:insert(mte.getMapObj())”. This will allow storyboard to unload the map object when the scene changes.

function scene:willEnterScene(event) local group = self.view --your code group:insert(mte.getMapObj()) end

You were seeing “Attempt to index field ‘?’ (a nil value)” because battle.json requires a tileset you were not loading in battle.lua. You should really pay attention to MTE’s printout statements!

WARNING: Failed to find image(dungeonFlat.png) 2013-08-30 20:29:35.480 Corona Simulator[2453:707] Searching for tileset dungeonFlat.png... 2013-08-30 20:29:35.480 Corona Simulator[2453:707] Checking Resource Directory... 2013-08-30 20:29:35.480 Corona Simulator[2453:707] WARNING: Failed to find image(dungeonFlat.png) 2013-08-30 20:29:35.480 Corona Simulator[2453:707] Checking battle.json folder... 2013-08-30 20:29:35.481 Corona Simulator[2453:707] WARNING: Failed to find image(battle.json/dungeonFlat.png) 2013-08-30 20:29:35.481 Corona Simulator[2453:707] Checking battle folder... 2013-08-30 20:29:35.481 Corona Simulator[2453:707] WARNING: Failed to find image(battle/dungeonFlat.png) 2013-08-30 20:29:35.481 Corona Simulator[2453:707] Checking dungeonFlat.png folder... 2013-08-30 20:29:35.482 Corona Simulator[2453:707] WARNING: Failed to find image(dungeonFlat.png/dungeonFlat.png) 2013-08-30 20:29:35.482 Corona Simulator[2453:707] Checking dungeonFlat folder... 2013-08-30 20:29:35.482 Corona Simulator[2453:707] WARNING: Failed to find image(dungeonFlat/dungeonFlat.png) 2013-08-30 20:29:35.482 Corona Simulator[2453:707] Could not find dungeonFlat.png 2013-08-30 20:29:35.482 Corona Simulator[2453:707] Use mte.getTilesetNames() and mte.loadTileset(name) to load tilesets programmatically.

Usually when the failsafe searches for the image file, something’s wrong somewhere. Anyway, load dungeonFlat.png and everything works fine… but not quite. Is battle.json missing a tileset? It contains tile ID’s above the highest ID in the dungeonFlat tileset.