Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to Save, in Codea

edited June 2013 in Questions Posts: 22

I an currently working on a project that has a score(increases every time I pick up an object). I would like to be able to save that score so every time I open up the app my score stays the same and I don't have to start over completely.

Comments

  • BriarfoxBriarfox Mod
    edited June 2013 Posts: 1,542

    Check out the codea reference for:

    saveLocalData()

    saveProjectData()

    saveGlobalData()

    http://twolivesleft.com/Codea/Reference/Storage.html#

    basically its:

    local score = 100
    saveProjectData("Saved_Score",score)
    
    readScore = readProjectData("Saved_Score")
    print(readScore)
    
  • Jmv38Jmv38 Mod
    Posts: 3,295

    Also there are some tricks with the type of what you save: numbers turn into strings or so. It is a bit of a headache at the beginning.

  • Jmv38Jmv38 Mod
    edited June 2013 Posts: 3,295

    This works:
    for saving i use global data, to keep the score even if i change the project name (or version). Tostring() makes sure i contol the type

    saveGlobalData("thisGameScore",tostring(score))
    

    When reading, i have to convert back to number

    score = tonumber(readGlobalData("thisGameScore")) or 0
    
  • Posts: 22

    Thanks, that really helped! My game is going to be much better now!

Sign In or Register to comment.