Corona SDK | Basic Setup & Other Useful Programs
Okay, so I thought I’d post a quick follow up on setting up Corona SDK. I figured this might be of use to anyone new to the system.
PRELIMINARY READING
Usually before I embark on learning anything new, I like to buy a good book on the subject and read it through – even if I’m not applying what I’m reading. This is something I’ve always done, no matter which subject, as it gives me a bit of a preview of what I’ll be getting into. Better to find out just what is entailed before spending your hard earned cash all that kit.
The book I chose to read was Corona SDK Mobile Game Development by Michelle M Fernandez. This I bought on Google Books via their Play store. Actually choosing a platform on which to read the book proved an effort in itself. I wanted a digital version, for maximum flexibility. I initially intended to buy the book for Amazon Kindle – until that is, I read the sample. The Kindle version suffered badly from a lack of formatting. This poor formatting made the book quite difficult to interpret, particularly in relation to the code samples. The Google Books version however, retained all the formatting of the original book – so that is the version I went with.
The book itself is an excellent introduction to the system. It is written very much with the beginner in mind. I did find, however, that the difficulty curve ramped steeply upwards around half way through, leading me to back-track a few times. I think this likely due to more LUA short-cuts making their way into the code samples. I look at the samples now and they are perfectly understandable, but when you are completely new to something even the basics can take a while to sink in.
USE AN EDITOR! (or ‘IDE’)
When I first started using Corona SDK, I found the stock interface quite basic. You create your code in the editor of your choice (such as NotePad++) and use the Corona Simulator software to test it. This shows your code running in a device simulator, along with any debug output. Once your code is running in the Simulator, you have the option to create an actual device build for testing on hardware. The bulk of your development and testing will likely take place within the Simulator, unless of course your app is heavily dependent on the touch interface.
There are a number of third party development tools available for Corona SDK which are designed to make coding easier, but I didn’t really take to any of them. Thankfully however, I eventually came across a fantastic little editor called ZeroBrane.
ZEROBRANE
You can use this utility for free – although I’m sure you’ll want to donate something to the author once you have used it. It essentially creates a coding environment for your LUA projects, highlighting syntax and generally making it easier to view. But more importantly, it allows the use of breakpoints. These enable you to debug your program, stepping through the code and tracking your variables. It also allows something called ‘live coding’ – where some values within your code may be adjusted in real-time, with the results visible inside of the running Simulator. How cool is that?
Setting up ZeroBrane is very easy. Once you have installed the software, all you need to do is set the LUA Interpreter to Corona (the software can also be used with many other SDKs).
One thing you MUST remember to do, is activate ZeroBrane debugger within your LUA code. This is done by adding the following line at the top of your code:
require (“mobdebug”).start()
Once this is done, the debug functions will operate perfectly. Using ZeroBrane completely transforms the feel of Corona SDK, making it a super fast, clean coding environment.
Now, I have a couple of suggestions when working with ZeroBrane. These are based on problems I encountered when I first started using it. I will list them here:
YOUR CODE RUNS FINE IN CORONA SIMULATOR, BUT DOES NOT RUN ON THE ACTUAL HARDWARE.
You MUST remember to comment out ZeroBrane’s REQUIRE statement (insert a – – at the start of the line) if you are going to test the code on your mobile device. If you attempt to run a build with the require statement active, it may freeze on the hardware (it did on my Android device).
YOUR PROGRAM IS SLUGGISH
I have noticed that running your code with the debugger active can sometimes slow the software down in the simulator. If you are running into performance issues when testing, try removing the require function (as above) and you will notice that things go back to normal.
YOU HAVE MISSING DEBUG INFO
I have found that not all of Corona Simulator’s debug output shows up in ZeroBrane’s built-in debug window. This can cause you to miss critical debug info. By default, ZeroBrane is set up to suppress the Corona Simulator’s own Debug window. However, after doing some digging, I discovered that it is indeed possible to keep the Corona Simulator’s debug window.
Run ZeroBrane and go to the following option: Edit > Preferences > Settings > User
Now, in the User Settings file, you need to add in the following line of code:
unhidewindow.ConsoleWindowClass = 0
Save the file. Now, you can’t see the effect of this immediately – you need to quit ZeroBrane and load it back up again. Run your program, and hey presto you should have access to the original Corona SDK debug window as well as ZeroBrane’s own window.
I had a couple of reasons for reinstating this debug window. Firstly, I missed a compiler message that was warning me of a compilation error within an entirely separate LUA program buried away in a project sub folder. I didn’t realise this at the time, but Corona SDK will compile absolutely everything in your project folder – not just the present directory. As I had some old broken test code hidden away in my working directory, it was tripping up the compiler. The project ran fine in Corona Simulator, but failed to build for the actual device.
The other reason for reinstating this debug window is that I appeared to be losing debug data that I was printing within my code. The missing values were quite possibly was due to invalid characters being sent to the window (something relating to the UTF-8 encoding). The Corona Debug Window does not have this problem and seems to show any rogue characters that are tagged onto the text.
Finally, I noticed that printing very long strings to the debug window also failed in ZeroBrane. They did however show up in the Corona Simulator Debug window.
Other than these very minor quibbles (which, let’s face it, are mostly my own fault!) I highly recommend using ZeroBrane if you are planning to learn Corona SDK.
It’s also worth noting, that Corona also released an ‘official’ editor towards the end of last year. Based on an existing IDE called Sublime Text, Corona released an extension to allow Corona coding within the editor. So, I decided to check that out.
I found the installation process quite bumpy. It failed on the first attempt, but ran okay on the second. I gave the editor a cursory test with my existing code and was generally quite impressed. But, I found it nowhere near as intuitive or friendly as ZeroBrane. That said, it is a very in-depth system, with a lot of features. An advanced programmer, or someone with existing familiarity with Sublime Text would probably love it.
But for me, the $70 price tag (something Corona failed to mention when encouraging users to download it) combined with the steep learning curve meant that it was something to look at again in the future. ZeroBrane does everything I need right now and you can pay what you like for the software. If you don’t make a penny with your app, then you don’t pay anything. If you make some money, then you can pay as much as you like for ZeroBrane.
FLOWCHARTING!
Having dabbled in a bit of code now, I have found myself producing some serious code spaghetti. I have discovered that unless you are careful, things get messy really quickly. When I studied programming back in 1990 (when computers were steam powered) we drew flowcharts. I hated them back then.
Well, thankfully you don’t have to use those stupid plastic flowchart templates any more. Now we have apps. And I’ve been using a great little app on my iPad called PureFlow. It’s free to use, but you might as well pay the 69p it costs to save out your charts in a variety of formats.
Even if you don’t plan your code with a chart initially, it’s very easy to knock one together for existing code. Once you have visualised your code in this way, it’s quite easy to see where optimisations can be made. Also, although this isn’t applicable to me right now, I do know that revisiting code in the future is always a major headache for the programmers I know. So I’m inclined to think that having a flowchart to view will make this re-familiarisation far quicker.
I also think that it could be useful for designing game flow, but I’ve yet to put that into practice.
I’ll probably make one more blog entry regarding Corona SDK, again for programming noobs (like me) who are just setting up. I had better sign off for now.