Ansca Mobile Corona SDK
 

This tutorial will teach you how to save and load data in your Corona SDK iPhone or Android application.

That’s right! It’s 9 AM on Sunday the 3rd and already I am posting a tutorial I didn’t expect to get done for at least another week.

I know a LOT of you have been eagerly awaiting this one and I figured I would get the month off to a good, productive start by staying up and writing this tutorial for all of you.

Everything you need to know to save and load data from/to your iPhone (or Android) app is right here. It’s a modified version of the code I used in Pocket Pet Rock and works perfectly.

I am very, very excited to have been able to get this done overnight – I think it will help a lot of people make better apps. (I know my next app is shaping up wonderfully thanks to being able to save and load data!)

DOWNLOAD IT HERE

Enjoy! (*You will want to open menu.lua first.)

I’m off for a well earned rest!

Peach Pellen :)

PS – If this helps you please consider donating. I rely on donations to get by. Although I don’t do this to get paid (I’d charge for email support if I did ;) ) I’m able to spend more time helping you and writing tutorials when I make some money doing it – it’s a fine balancing act between this and making my own apps in order to scrape by.

If you cannot afford to donate please consider tweeting this, Facebook-ing it, following me on Twitter or liking Techority using the box in the sidebar.

Thank you!

Like this post? Subscribe to the monthly newsletter!

 

  55 Responses to “How To Save And Load Data In Your App”

  1. No worries, you mean when you resume you app you want to return to the last scene played?

    If so, you’d save a fourth thing after your threelock, like lastScene = “menu” or whatever. Then on each scene you’d do lastScene = “scene1″ or whatever the scene is called.

    Then at the top of the menu, you’d do a function to change the scene to lastScene with director.

    Make sense? :)

  2. Hi Peach,

    thank you very much for your great work!

    I havea little question about this:

    in the menu.lua, line 147, you wrote “if _G.twolock-0 == 0 then…” why do we need to add the “-0″ behind _G.twolock? I actually noticed that it doesn’t work without but I don’t understand what it does….

    Thank you,
    Best regards,
    Robin

  3. No worries Robin,

    I did that because I was half asleep, I think ;) Really I should have/could have used tonumber()

    The reason is because it’s a string, but we want to change it to a number – make sense?

    If not check out the tonumber() API on the Corona website for more specific into :)

    Peach

  4. Thanks for the sample code.

    Does this data survive application updates?

    Example: Say I’m using this text file to store which levels in a game a user has passed. If I publish a simple fix to the app store I want to be sure that doesn’t result in the user’s level record being wiped.

  5. Hi Jade, recognize the pic – thanks for the Twitter follow :)

    I’d actually recommend using Jon Beebe’s Games Class for saving and loading data. It didn’t exist when this was written but is much easier to use and also easier to update the app and not risk losing any data.

    Peach :)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

   
Ansca Mobile Corona SDK
© 2012 Techority Suffusion theme by Sayontan Sinha