Portal-Studios Blog

Differences Between Basic AS3 and Lua (Corona SDK) Part 1

Seeing how the market has shifted to mobile gaming and how Flash has a long way to go before it is a good option for iOS development I have been looking into alternatives to make mobile apps. A friend of mine recommended Corona SDK so I’ve put some time in with Corona and I’m very happy I did.

Let me give you an idea of my skillset. I’m a self taught programmer who mainly uses movie clips and timelines to make my games in Flash. I am not one to use Flex or Flash Builder to set up my projects, I like to see things on the timeline. I learned to program in AS1, switched to AS2, and held out using AS2 for a long time because AS3 was confusing to me, finally I learned AS3 and my skills have slowly improved over the years. I don’t know any other programming languages other than Actionscript, PHP and HTML, basically stuff I need to know for web design.

I’m about a month or so into using Corona and I’ve been able to pick up on it pretty fast. There are some major differences between Lua and AS3 so I’m compiling into a list for other Flash devs who follow in my footsteps. I was scratching my head a few times and there wasn’t really anything out there that I could find that put the differences in plain English. So I’m going to take a stab at it.

Here are some key areas that you might find confusing, I’m going to try to explain them from a AS2-AS3 developer perspective.

File Structure:

With Corona SDK you will always start with a “main.lua” file. This is the starting point for all your coding. You can break up your code into several files to try to keep things neat and tidy by using “require(‘filename’)” this is covered fairly clearly in the documentation of Lua.

You can use the structure defined here to build multiple scenes into your game: http://techority.com/2010/11/19/how-to-use-scenesscreens-in-corona/

However if you to use this be sure to create your global variables in “main.lua” if you want to access them everywhere else. Otherwise your code might error out looking for a variable.

If Statement Structure:

If you are trying to learn Lua you more than likely already noticed this.  If statements don’t need parentheses and they don’t use brackets to enclose the statement.

so this…

if ( !myVar) {
trace(‘Hello, World!’);

becomes this…

if not myVar then
print(‘Hello, World!’)

Logical Operators:

If statements wouldn’t be very useful without the ability to check multiple things at once.  Remember that Lua uses words rather than symbols for most of these.  So “&&” becomes “and” , “||” becomes “or”, and “!” becomes “not”.    There are several other differences on this so if you want to read about them go here.  http://lua-users.org/wiki/ExpressionsTutorial

Loop structure

Not So Random Numbers:

Random numbers in Flash always seem at least fairly random. However on several devices random numbers are always the same sequence based off a default seed number. You need to change the seed for your random numbers to make sure the numbers are more random. So using a number that will always be different for a seed, like the current time and date will make your random numbers works better.

math.randomseed( os.time() )

Read more here… http://lua-users.org/wiki/MathLibraryTutorial

Missing functions:

This is irksome, things you take for granted in AS3 are missing.  There are quite a few that are either missing or are called by another name.  Here is a quick list of the ones that I’ve come across that I really miss.

Array Funtions:

Arrays in Lua are called tables, and several of the functions that you are used to as a flash developer are not available in Lua.

First off to make a table you simply do this:

myTable = { }


myTable = {1,2,3,4 }


myTable = {name = value, name = value}

Your table is ready to use. But you don’t have the same tools at your disposal as in Actionscript. You have nothing that works like “pop()” or “splice()”. Here are a few functions you need to be familiar with to work with tables.  Notice that you do not call the name of the table then insert to insert into a table.  You tell the function what table is effected by passing the table name as an parameter.

table.insert( myTable, #)

table.remove( myTable, #)

Here is a link to a pretty good writeup on tables: http://lua-users.org/wiki/TablesTutorial

Comparing tables seems to not work the same way as in actionscript.  I might be doing it wrong but comparing


Need to skip to the next itteration of the loop that you are currently running? Lua does not offer this functionality.

Switch statements:

You can’t use switch statements in Lua, you have to either use a massive if else statement, or a table. Here is a link to a better explanation:

There are quite a few other things that I want to point out but this post is getting rather long so I’m going to make it a multiple part post.  Look for more information in the near future in part 2.

AS3 Flash: Low CPU Clouds Animation

AS3 Flash: Low CPU Clouds Animation – Perfect for Mobile

In our our recent tutorial on clouds effect via BitmapData.perlinNoise and ColorMatrixFilter, we presented a nice clouds animation but very CPU intensive and not suitable for larger images or for mobile devices. Here we present a version that is extremely CPU efficient, runs very well on Android 2.2, and can be used to generate large images. In the two examples linked below we generate 500 by 380 animations. Click each screen shot or the corresponding text link to open a Flash movie.

Simpler and highly optimized animation:
An interesting two-layered effect:

Click here to find out more…

Simple Flash Trace Debug Mode

I thought I would share a little snippet I use from time to time to allow me to turn on and off the trace function in my Flash work.

Basically instead of typing “trace(‘hello world’);” you type “debug(‘hello world’);”.

Then once you are done developing the swf you just change the debugMode variable to false and turn off all your trace functions to save a good bit of processing in the final product. It’s quite handy.

Here is the code I use:

var debugMode:Boolean = true;

function debug(STRING:String){

Lifeguard Larry Deluxe now a Facebook Game

I put together a Facebook app for my new game Lifeguard Larry Deluxe. I’m actually pretty happy with how it turned out and I’m pretty sure that I will be integrating more social networking features into my games from this point on.

The hurtle that I was able to get over was making the facebook calls work from the swf itself. The swf currently has to be on facebook to work properly but I believe I might be able to figure out a way to make it work when the user isn’t on facebook.

Click here to play Lifeguard Larry Deluxe on Facebook.

Play Lifeguard Larry Deluxe

Lifeguard Larry Deluxe Flash Game

A screenshot from the Lifeguard Larry Deluxe Flash Game

This is a funny flash game where you have one minute to find a way to save the drowning boy in the pool. It is a little morbid but it’s really funny and memorable and people like games that surprise them. This was a project that was made with another artist and a musician. Click see more to play the game.
Click here to find out more…

Primary Flash game

Primary is an action platformer puzzle game where you control Roy. A HUEman super soldier who must climb to the top of Prizim tower to stop an invasion of color eating monsters who want to lay waste to his planet.
Click here to find out more…

Attending the Flash Gaming Summit.

I will be away from March 7th through the 9th to head out to San Francisco for the Flash Gaming Summit. I will be taking many pictures and I will be sharing them here on my blog with you.

I will be reachable by phone if you need to contact me otherwise please have a great weekend and I will talk with you on Wednesday!

Flash Special Effects: Smoke

Hey in my travels around the internet I stumble across some really neat things. Case in point is a great tutorial for animators about how to animate smoke. It’s really worth checking out if you are an animator like myself.
Here is a link.

Completing another game… Looking back.

So last summer I started a project with another developer online.  To make an action puzzle platformer game.   I have been working on this game for months and months now and after many ups and downs it’s nearly done!   I have spent all night putting elements into the game such as leaderboards, an intro and ending animation.    I’m working on the menus tonight, I am still waiting on some new music for the game to be completed but hopefully that won’t hold us up to much.

The game’s name is Primary.  It is about your character named Roy who is a man made of color, he can phase between the primary colors, red, yellow, and blue.  When he phases his body and his powers change, allowing you to solve puzzles and fight enemies.

It’s hopefully going to be popular, though you can never really tell.  I have been developing flash games for a long time now and this is one of my more complex personal endeavors… and though I don’t expect it to be a Bejeweled type hit I do hope for a few million plays in the first month.  That would be nice.

I have had several things happen to me while I was developing this game.  I became an uncle, I started freelancing again, and I started the meetup group that I have been leading.  I’m sure there are many more things but those are the big ones that come to mind.  It’s funny how I look back on my games and I don’t think about the games or the money that I get from them… I think about what happened to me in the time it to to develop the game.

When making a game the developer knows that game inside and out, and honestly by the time you are done developing and testing a game you can’t stand to see it anymore.  It’s a ton of work and anyone who creates games does it cause they love it.  So I’m really excited to be done with my new game and about ready to send it out into the world to sink or swim.  I’m so nervous… I hope it makes friends.

Here are some screenshots:

Lip Syncing in Flash

Hey I found a really nice tutorial on Lip syncing animated characters in flash. I already use most of these tips but the order that the phonims are added was something I never thought of. Here is a link.