Hi
In my App I’d like to transfer data between different two scenes. I also use SQLite to populate the screen in one scene. This then generates different buttons. My goal is to send the button Id to the next scene, where I then generate the level (again from an SQLite table).
I have read this article(http://www.coronalabs.com/blog/2012/08/07/managing-state-between-scenes/), and many others, but just couldn’t find a solution.
Could someone please help?
My code in Scene1:
local function onSceneTouch( self, event ) if event.phase == "began" then storyboard.gotoScene( "scene2", "fade", 400) return true end end -- Called when the scene's view does not exist: function scene:createScene( event ) local screenGroup = self.view --BEGIN SQLITE require "sqlite3" --Open data.db. If the file doesn't exist it will be created local path = system.pathForFile("data.db", system.DocumentsDirectory) db = sqlite3.open( path ) --Handle the applicationExit event to close the db local function onSystemEvent( event ) if( event.type == "applicationExit" ) then db:close() end end --setup the system listener to catch applicationExit Runtime:addEventListener( "system", onSystemEvent ) --END SQLITE end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local screenGroup = self.view function newButton ( routeId, routeName, status ) local self = {} self.routeId = routeId self.routeName = routeName self.status = status function self:createButton() local pos = "images/pos.png" local neg = "images/neg.png" if (self.status == 1) then image = display.newImage( pos ) else image = display.newImage( neg ) end image.x = 30 + (self.routeId \* 90) image.y = 250 --+ (self.routeId \* 50) screenGroup:insert( image ) image.touch = onSceneTouch image:addEventListener( "touch", image ) end return self end local buttons = {} --print all the table contents for row in db:nrows("SELECT \* FROM main") do local routeId = row.route\_id local routeName = row.route\_name local difficulty = row.difficulty local status = row.climbed\_status local t = display.newText(routeName, 0 + (90 \* row.route\_id), 310, native.systemFont, 20) t:setTextColor(255,255,255) screenGroup:insert( t ) local i = newButton( routeId, routeName, status ) i:createButton() buttons[routeId] = { routeId = routeId } end end
And then in Scene2 I have:
local routeId = event.routeId