How can i easily implement a save and load system

Hi

My game currently has a main menu and multiple levels. Each level is on a new screen.

After each level is completed i would like it to save (either auto save or maybe user saves manually once level is complete with a pop up save button).

I would then like the user to be able to load this from the main menu.

I have tried looking at all the samples and older forum post but its getting really confusing.

From what i can gather from these examples is that i need to create a database, have each level write to this database and have a load from database function in my main menu.

Please could someone help by making a really easy to use guide for implementing this. [import]uid: 24981 topic_id: 5879 reply_id: 305879[/import]

Just a bit more detail on what i would like to be saved and loaded.

Once the level is complete, save this. When user chooses load from main menu The next level (screen) will be loaded.

I have read that using screens for levels isn’t the best way to go about creating games, however i feel comfortable using them at the moment as a beginner

All help is appreciated. [import]uid: 24981 topic_id: 5879 reply_id: 20143[/import]

Here’s a save and restore state sample code:
http://developer.anscamobile.com/code/save-and-restore-state

[lua]local myBox = display.newRect(0, 0, 40, 40)
myBox:setFillColor(255, 255, 0)

local function moveBox( event )
myBox.x = event.x
myBox.y = event.y
end

local function resumeStart()
– restore previous state
local path = system.pathForFile( “data.txt”, system.DocumentsDirectory )
local file = io.open( path, “r” )

if file then
print(“loading previous state variables…”)
local contents = file:read( “*a” )

– separate the variables into a table using a helper function
local prevState = explode(", ", contents)

myBox.x = prevState[1]
myBox.y = prevState[2]

io.close( file )
else
myBox.x = display.stageWidth/2
myBox.y = display.stageHeight/2
end
end

local function onSystemEvent( event )
if( event.type == “applicationExit” ) then
– create a file to save current state
local path = system.pathForFile( “data.txt”, system.DocumentsDirectory )
local file = io.open( path, “w+b” )

– save current state variables in comma separated list
file:write( myBox.x …", "… myBox.y )
io.close( file )
end
end

– explode helper function
function explode(div,str)
if (div==’’) then return false end
local pos,arr = 0,{}
– for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) – Attach chars left of current divider
pos = sp + 1 – Jump past current divider
end
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr
end

local function init()
– start and resume from previous state, if any
resumeStart()

myBox:addEventListener(“touch”, moveBox)

Runtime:addEventListener( “system”, onSystemEvent )
end

–start the program
init()[/lua] [import]uid: 8045 topic_id: 5879 reply_id: 21635[/import]