Problem when saving to txt using exchange scenes

To better illustrate my problem mentioned in this post -> http://forums.coronalabs.com/topic/50053-thegame-scene-for-gamover-automatically-going-to-mainlua/ created an example with 3 scenes where the Last scene I record a score in a txt. Scene 3 automatically returns to the scene 1 impossible to use the options that are there. 
 
Follow the 4 sample files to better understand:
 
main.lua
 

-- Esconde o status bar do dispositivo display.setStatusBar(display.HiddenStatusBar) -- Dimensões do dispositivo e centro do mesmo w = display.contentWidth h = display.contentHeight centerX = w \* 0.5 centerY = h \* 0.5 -- Carrega composer composer = require( "composer" ) scene = composer.newScene() composer.gotoScene( "scene1" )

scene1.lua

local scene = composer.newScene() -- Touch event listener local function onSceneTouch( self, event ) if event.phase == "began" then composer.gotoScene( "scene2", "fade", 300 ) return true end end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local goToScene2 = display.newText("Go to scene 2", centerX, centerY\*1.2, native.systemFont, 26 ) goToScene2:setFillColor( 255,255,255 ) goToScene2.touch = onSceneTouch sceneGroup:insert( goToScene2 ) goToScene2:addEventListener( "touch", goToScene2 ) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. -- Remove o botão de play end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

scene2.lua

local scene = composer.newScene() -- Touch event listener local function onSceneTouch( self, event ) if event.phase == "began" then composer.gotoScene( "scene3", "fade", 300 ) return true end end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local goToScene3 = display.newText("Go to scene 3", centerX, centerY\*1.2, native.systemFont, 26 ) goToScene3:setFillColor( 255,255,255 ) goToScene3.touch = onSceneTouch sceneGroup:insert( goToScene3 ) goToScene3:addEventListener( "touch", goToScene3 ) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. -- Remove o botão de play end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

scene3.lua(Here I saved in txt file)

function saveInFile(saveData) local path = system.pathForFile( "file.txt", system.ResourceDirectory ) -- DocumentDirectory local file = io.open( path, "a+" ) file:write( saveData .. '\n' ) io.close( file ) file = nil end local scene = composer.newScene() -- Touch event listener local function onSceneTouch( self, event ) if event.phase == "began" then composer.gotoScene( "scene1", "fade", 300 ) return true end end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local backToScene1 = display.newText("Back to scene 1", centerX, centerY\*1.2, native.systemFont, 26 ) backToScene1:setFillColor( 255,255,255 ) backToScene1.touch = onSceneTouch sceneGroup:insert( backToScene1 ) saveInFile(3) backToScene1:addEventListener( "touch", backToScene1 ) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. -- Remove o botão de play end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Does anyone have an idea to solve this?

I got the solution! The problem was simply using the ‘ResourceDirectory’, changed to ‘documentsDirectory’ and it worked.

Does anyone have an idea to solve this?

I got the solution! The problem was simply using the ‘ResourceDirectory’, changed to ‘documentsDirectory’ and it worked.