When wanting to save a value in a text file, the application is restarted within the simulator.

A=0 B=0 C=0 D="000" Boton1=display.newRect (100,100,50,50) Boton2=display.newRect (200,100,50,50) Boton3=display.newRect (300,100,50,50) Boton4=display.newRect (200,600,100,50) Boton4:setFillColor(255,0,0) Info = display.newText( A, 100, 200, "GillSans", 40) Info:setTextColor(255,255,255) Info2 = display.newText( B, 200, 200, "GillSans", 40) Info2:setTextColor(255,255,255) Info3 = display.newText( C, 300, 200, "GillSans", 40) Info3:setTextColor(255,255,255) Info4 = display.newText( D, 200, 400, "GillSans", 120) Info4:setTextColor(255,0,0) function Mutar1 (event) A=A+1 if A\>1 then A=0 end Info.text=A Info4.text=A..B..C end function Mutar2 (event) B=B+1 if B\>1 then B=0 end Info2.text=B Info4.text=A..B..C end function Mutar3 (event) C=C+1 if C\>1 then C=0 end Info3.text=C Info4.text=A..B..C end function Agregar (event) path = system.pathForFile( "Texto.txt" ) file = io.open( path, "w" ) file:write(Info4.text) io.close( file ) end Boton1:addEventListener("tap", Mutar1) Boton2:addEventListener("tap", Mutar2) Boton3:addEventListener("tap", Mutar3) Boton4:addEventListener("tap", Agregar)

This is all the code. The three white buttons allow you to build a combination of ones and zeros from “000” to “111”.

The red button opens the text file, saves the value and closes the file.

To run the application alone you need to create a text file called “Texto.txt” and place it inside the same folder of the application.

The application works perfectly, the data saves it. All perfect. But the application restarts. I want to know why this happens. It would not have to be restarted.

Sounds like you’re saving files in the game code folder?  If so, you may have the ‘reload on change’ option on.

You can change that ‘simulator’ option under preferences.

This is handy, but sometimes gets in the way of other work on your game.

Be aware that this will not work on mobile.

You should use the documents folder.

@SGS is right.  If your app is writing to the ResourceDirectory while running… you can expect that to fail for all production builds.  You need to use the DocumentsDirectory or another that is writable.

Sounds like you’re saving files in the game code folder?  If so, you may have the ‘reload on change’ option on.

You can change that ‘simulator’ option under preferences.

This is handy, but sometimes gets in the way of other work on your game.

Be aware that this will not work on mobile.

You should use the documents folder.

@SGS is right.  If your app is writing to the ResourceDirectory while running… you can expect that to fail for all production builds.  You need to use the DocumentsDirectory or another that is writable.