Save and Restore Data

Most games need data to be saved. Some data is relative to the game content (levels, items), while some is relative to the player (score, last position). Once again, Corona SDK makes the process quite easy.

The JSON File Format

JSON (JavaScript Object Notation) has replaced XML (Extensible Markup Language) in the world of independent game programmers. It’s a way to write data in text. This text is then saved in a file. This file is then read to restore data when needed.

JSON is smart, light, easy to read and write, and is supported by almost all the programming languages.

Another strength: this format is Lua-friendly, as it perfectly mirrors the Lua tables!

Look at this Lua table:

And now, translated in JSON:

If ...

Get Create 2D Mobile Games with Corona SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.