Best Practices in Corona SDK


Some time ago I’ve posted a few tips & tricks when dealing with Corona SDK, and finally I got my hands on posting another portion of useful things in there! Below you can read about code style, saving persistent data, and getting community help.

Code style and work environment

  • Keep all in module manageable functions
  • Use camel-case style for functions and variables
  • Keep in mind 200 max variables limit per module
  • Always add one blank line to separate nested blocks, for example before the if block above (more than one line is unnecessary)
  • Keep game settings as a separate class, so it’s not mixed with screen’s lifecycles
  • Sublime 3 Beta is recommended for the development and for Sublime Corona plugin

Further info

Best Practices for Organizing Projects

Tutorial: The value of well-formatted code

Tutorial: Scope for beginners

Help and Examples

  • Follow Corona SDK blog to get useful examples, tutorials, track Corona SDK news and team’s hangout meetings
  • Speak about your issues and get help on CoronaLabs forum
  • Check Sample Projects in Corona Simulator. Just open Corona Simulator, click on Help > Sample Projects… and you will see dozens of projects. Because of the variety, there’s a good chance you will find something that you can use in your own game. On Windows 7/8/10, typical location for sample code is C:Program Files (x86)Corona LabsCorona SDKSample Code. Also, you can find Sample Code videos and articles on Corona University

Read and save files

This is quite a broad topic and obviously tied up to platform’s specifics. But, doesn’t matter the platform, the most convenient way is to save your game settings as a .json file. It is then easy to modify, even by non-programmers, and also easy to manage. The default path to save non-temporary, non-cache files, is system.DocumentsDirectory.

If you want to do more, you have to remember about restrictions, like, on Android there is no something like system.ResourceDirectory, because the resources are packed inside the apk file, and on iOS you can automatically back up files in system.DocumentsDirectory to iCloud. So, it’s also the matter of understanding the restrictions and what Corona SDK offers on particular platform.

For loading and saving persistent data, I recommend loadsave library. Just add loadsave.lua file to your utils folder and use it like this:

local C = require( "globaldata" ) 
local loadsave = require("utils.loadsave") 
C.soundSettings.musicOn = false 

But, what happens when you save a file in Corona Simulator? Again, if you’re on Windows 7/8/10, the path should normally be C:Userssome_userAppDataRoamingCorona LabsCorona SimulatorSandboxsome_game_title-some_random_sequenceDocuments

Further info

Reading and Writing Files

Thank you so much for reading!

Like and share:

Published by

Tonia Tkachuk

I'm an Android Developer, writing code for living and for fun. Love beautiful apps with a clean code inside. Enjoy travelling and reading.

One thought on “Best Practices in Corona SDK”

  1. Pingback: URL

Leave a Reply

Your email address will not be published.