Saving data- Help!!

i need to store data (score) and need to retrieve it when i open the next time. I followed peach’s tutorial, but i could not understand it properly. :frowning: Can some one help me where i am wrong .

_G.level1starscollected=3 --this is the data i need to store
saveit.save()
–Here is the saveit.lua that i used from peach’s tutorial :

module(…, package.seeall)

function save( event )
local path = system.pathForFile( “ourdata.txt”, system.DocumentsDirectory )
local file = io.open( path, “w+b” )
file:write( _G.level1starscollected)
io.close( file )
end

am i missing some code.?
Please help.
Thank you. [import]uid: 76873 topic_id: 17772 reply_id: 317772[/import]

Hey there,

That “tutorial” is older and not the best way of doing things - was more about cobbling things together just to make it work :wink:

I would suggest you take a look at this thread; http://developer.anscamobile.com/forum/2011/10/19/savingloadind-data-easier-way

Stacks of useful info in there :slight_smile:

Peach [import]uid: 52491 topic_id: 17772 reply_id: 67877[/import]