Advertisement
Hendrix000007

read writefile

Feb 27th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. --------------------
  2. --READ AND WRITE TO FILE [cred to Bogdan Vladu and LevelHelper]
  3. -- THIS ONE HANDLES THE VARIABLE currentLevel
  4. ----------------------
  5.  
  6. function saveProgress( currentLevel )          
  7.     local path = system.pathForFile( "myTextfile.txt", system.DocumentsDirectory )                
  8.     local file = io.open( path, "w+b" )
  9.                
  10.     file:write(currentLevel)          
  11.     io.close( file )
  12. end
  13.  
  14. function loadProgress()
  15.            
  16.     local currentLevel = 1
  17.  
  18.     local path = system.pathForFile( "myTextfile.txt", system.DocumentsDirectory )                
  19.     local file = io.open( path, "r" )
  20.  
  21.     if file then
  22.         local contents = file:read( "*a" )
  23.        
  24.         currentLevel = tonumber(contents)
  25.        
  26.         io.close( file )
  27.     end
  28.  
  29.     return currentLevel
  30.  
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement