New to Corona & new to Lua

Hello, So I’ve just downloaded Corona SDK and took a look at the “university” section, I got myself little familiar with Lua and it’s syntaxes and tables, but as I understand, Lua is not OO and Corona is not component based, so my question here is, what is the best way to structure a game? let’s say a game that has a main menu, several levels, and few reusable assets like enemies, player, projectiles. Will I be forced to keep repeating the same logic in each scene file.lua. or is there some simple way to reuse all my functions plus overriding them when needed? 

Any tips regarding best practices, or tutorials would be appreciated.

Thanks. 

PS: is there a light node/object in Corona?!

  1. Lua isn’t strictly OOP, but … as I said in this answer it can achieve many OOP like designs and patterns:

https://forums.coronalabs.com/topic/61028-do-you-recommend-corona-as-a-reliable-2d-mobile-game-engine/

  1. You can create ‘components’ using Lua.

  2. You can also create modules which is the #1 people address code re-use: 

https://coronalabs.com/blog/2012/08/28/how-external-modules-work-in-corona/

Thank you very much for clearing some stuff, but would you please elaborate more on this: 

  1. You can create ‘components’ using Lua.

and maybe some tips regarding my first post on this:

what is the best way to structure a game with multiple levels?

I’m about 2-3 months into this, and I guess what I can say is that lua does not have any of this built-in. It’s very lightweight and leaves it up to you, as the developer, to create an architecture that suits your needs. For OOP, I’ll suggest you read http://www.lua.org/pil/16.html

For components, I have decided to declare a global “package” table and create accessible modules in that table. The most basic way is is at the bottom of a file, I do this:

PR = PR or {} PR.Utils = statics

Where “PR” is my package name, “Utils” is my module and statics is a table containing references to functions. Thus, I can call a function from any file with lines like this:

require("PR.Utils") PR.Utils.foo(0, true)

Which brings me to structure because we just did a “require” statement. Corona likes to have a main.lua file running with every other file path relative to that. So, my “bin” folder looks something like this:

- bin/ - PR/ \*Utils.lua - Game/ \*World.lua \*Hero.lua \*main.lua

Because main.lua is the starting point for Corona, every require statement can be made relative to that, giving us simple statements like:

require("PR.Utils") require("Game.Hero")

Hope that helps!

@Abdou23

“what is the best way to structure a game with multiple levels?”

The best way to structure your project is in a way that works for you and fits your personal style.   However, beyond that ‘generic’ advice, these are all practices I use:

  • config.lua - Unless you’re very experienced and if you like knowing your design resolution, use a fixed design resolution instead of one of the ‘calculate best width/height’ approaches.
  • Use sub-folders for assets and scripts.  Nothing should live in the root folder except:
    • main.lua
    • config.lua
    • buid.settings
    • launch images
    • icons
    • everything else should be in sub-folders.
  • Use Modules for common code.
  • Use plugins and libraries when they save you effort and improve your project.
  • Do not assume you ‘must’ use compose scene manager.  You may very well be able to manage your own scenes.
  • If you use composer, use a fixed standard scene file layout and minimize the code in it.  Let the modules you write contain all of the app logic. i.e Don’t make 2000 line long ‘create()’ methods.

@Abdou23

You asked me to give more details on this statement:  " You can create ‘components’ using Lua."

As much as I wish I could give you a ‘simple example’, I cannot.  This is a very advanced topic.

Having said that, you  should feel free to dig through my old experimental behaviors code:

http://github.com/roaminggamer/SSKCorona/tree/master/ssk/behaviors

PS -

Neither Lua nor Corona has the concept of a ‘component’.  So there is no shortcut, “This is the right way, and only way, to design them.”  

Instead, you would design a component system based on your needs and understanding of Lua/Corona.  This is why it is advanced and why my experiment may not be grokable or useful to you.

Thanks a lot, you really are helping kickstart my  development with Corona, but still there are some issues that worries me about it, for example this sdk/framework/engine or whatever has been around for couple of years now, but still it lacks some basic features that is now standard in other engines, for example, Light effect, Particle systems, Wi-Fi testing(or even wired testing) I also noticed that the Composer GUI is currently suspended for some reason? I’m worried that devs. only maintain Corona and just make sure it only stays compatible with newer platforms OS releases without upgrading the SDK or it’s features, but perhaps I’m mistaken here. 

@Abdou23

I’m reading your post now, but I have a small request.  

Please use paragraphs with line breaks between them to help break up your posts.  I find them hard to read and while I want to help, I have only a little time to do so.  

Anything you can do to make it easier to help you… well I’m sure you get the idea.  Thanks!

Also try bullet list…

Example - Your post ‘re-edited’ for ease of reading…

Thanks a lot, you really are helping kickstart my  development with Corona, but still there are some issues that worry me about it.

For example this sdk/framework/engine or whatever has been around for couple of years now, but still it lacks some basic features that is now standard in other engines:

  1. Light effect,
  2. Particle systems,
  3. Wi-Fi testing(or even wired testing)

I also noticed that the Composer GUI is currently suspended for some reason?

I’m worried that devs. only maintain Corona and just make sure it only stays compatible with newer platforms OS releases without upgrading the SDK or it’s features, but perhaps I’m mistaken here. 

Answers to re-formatted question(s).

>> Part 1 - "sdk/framework/engine or whatever "

Corona is an SDK (read here for difference between an SDK and an Engine.)

In my opinion, SDKs are better than engines because:

  • an Engine may have more ‘features’, you are typically locked in to doing things a certain way, or into re-coding the engine.  
  • Whereas, an SDK may be missing a ‘feature’, but that feature can be easily added by using kit parts (elements of the SDK), or via 3rd party solutions.  

At the end of the day SDKs are more flexible and user friendly.

>> Part 2 the features you said are missing…

  1. Light Effect - I’m not sure what you mean by this…
  • Do you mean 3D lighting effects?  If so, then as this is as SDK for 2D games.
  • Do you mean calculated lighting?  If so, this is supported via shaders. (Links: 1, 2, 3, 4,  check them all and dig more from there.)
  • Is this a specific thing I (should but,) don’t know about?  If so, share some example links to this ‘Light System’
  1.  Particle Systems - This is supported a few ways: ( Built in libraries 1, 2;  3rd party solutions: CBE, Prism, Particle Candy.

  2. Wi-Fi Testing - Again, not sure what you mean here…

  • Can you test for a wifi connection?   No , but you can check for an internet connection and since  you don’t care if your connection is wired, wifi, or phone network (for the most part), that is enough.
  • Can you side-load apps to your device via WiFi?   Yes, but not as a feature of Corona.  This is a development environment feature you’ll have to work out on your own or as for help from someone on.  (Not me as I use wired side-loading.)
  • Can you modify your code locally (on PC/Mac) and have the app (nearly) instantly update on device for fast testing?   Yes , and this is a supported feature of Corona. 

Note: I took significant time and effort to answer this post, so I’d appreciate some info in return.  How are you learning to use Corona?

(I’m not picking on you here.  I want to understand your technique/approach so I can help better and so I can see where your friction points are.)

Specifically are you:

  • Reading the blogs, both old and new? Y/N
  • Searching the forms? Y/N
  • Reading the API Docs -  Y/N
  • Using Google to make searches like this?   Y/N
    • Corona SDK Particle System

PS - I used coloring in this post.  Generally that is frowned upon, but I did so because I wanted to be very clear and make the post easier to browse quickly for TL&DR folks.

1. Light Effect :

Meaning “Light Node” that illuminates the scene and make objects cast shadows, like the ones you find in Cocos2d or SpriteKit

2.   Particle Systems  -:

Meaning effects like fire, explosion, lightning. I took a look at the links, the first one is related to the physics engine, the docs are not clear enough on why would I set collision properties on an effect like that, it might be something other that what I meant, others are 3rd party tools.
  

Can you modify your code locally (on PC/Mac) and have the app (nearly) instantly update on device**  for fast testing?  Yes, and this is a supported feature of Corona.**

But I read something about having Corona compile first in the cloud and then push it on the phone?!
 

Note: I took significant time and effort to answer this post, so I’d appreciate some info in return.  How are you learning to use Corona?

I appreciate that.
 
 

(I’m not picking on you here.  I want to understand your technique/approach so I can help better and so I can see where your friction points are.)

 
Specifically are you:

  • Reading the blogs, both old and new?  N

  • Searching the forms**?** Y
    Reading the API Docs - Y

Using Google to make searches like this?

  • Corona SDK Particle System

Y, and also searching for tutorials to follow, I was disappointed when I didn’t find any official tutorials by Corona team, they are all just examples of different features, I wanted to know the official and recommended way to structure and build an entire game with Corona.

Also, you forgot to mention the part about the Composer GUI, I read that it’s been suspended for a while now. 
 
I come from Objective-C, SWIFT, Xcode, SpriteKit background, I made few apps and games with it already, I tried several others engines but did not get very comfortable with any, Unity was the best of them all but a little pricey for us. As a developer, I want something more versatile than SpriteKit and also multiplatform.
 
My worries are that I invest time, effort and money in developing with Corona just to find it fading out or getting left behind in a year or so, I had to ask myself some questions like:

  • Why some of those features are not yet integrated(mentioned above)
  • Why did not the devs create a fully integrated IDE
  • Why a feature like 3D touch (for example) had to be requested by the users in order to get implemented

And others that I won’t bother you with because I don’t want to be more burden than I already am.
 
I recently received a beta to Defold which I’m currently testing, I’m torn between it and this one, on one hand Corona has been around for a couple of years, with a huge community, on the other, Defold already looks  much more advanced. 
 
Difficult decision to make so I need to weigh all my options.
 
Thank you again for taking up the time to assist me on this.

PS: I tried putting each of your quotes inside actual quotes to better format the post, but the editor complained of too many quotes.

@Abdou23,

  1. Thanks for the formatting.  It was easier to read.

  2. Composer Editor (not scene library) - I’m not clear on the status of that.  I don’t personally use it (I do use the scene library).

  3. Particles - I’d suggest the second link and/or Calebs work Prism/CBE depending on what you need.  They each have different uses.

  4. Blogs - I know it is hard to search them, but man there is a ton of great info in the blogs over the past few years.

  5. Defold - I was on the beta and while I’m not sold on it I see some things they do better that I’m looking into addressing here.

  6. IDE - You mean like Unity’s IDE?  Code editor, object inspector, performance tools, etc.?  This is very interesting topic to me, but I’ll say little more for now other than I’m considering how this could be resolved.

  7. Burden?  - Totally not a burden.  Welcome to the community and thanks for asking interesting questions.

-Ed

Thank you very much, appreciate everything. Glad to be part of the community :slight_smile:

  1. Lua isn’t strictly OOP, but … as I said in this answer it can achieve many OOP like designs and patterns:

https://forums.coronalabs.com/topic/61028-do-you-recommend-corona-as-a-reliable-2d-mobile-game-engine/

  1. You can create ‘components’ using Lua.

  2. You can also create modules which is the #1 people address code re-use: 

https://coronalabs.com/blog/2012/08/28/how-external-modules-work-in-corona/

Thank you very much for clearing some stuff, but would you please elaborate more on this: 

  1. You can create ‘components’ using Lua.

and maybe some tips regarding my first post on this:

what is the best way to structure a game with multiple levels?

I’m about 2-3 months into this, and I guess what I can say is that lua does not have any of this built-in. It’s very lightweight and leaves it up to you, as the developer, to create an architecture that suits your needs. For OOP, I’ll suggest you read http://www.lua.org/pil/16.html

For components, I have decided to declare a global “package” table and create accessible modules in that table. The most basic way is is at the bottom of a file, I do this:

PR = PR or {} PR.Utils = statics

Where “PR” is my package name, “Utils” is my module and statics is a table containing references to functions. Thus, I can call a function from any file with lines like this:

require("PR.Utils") PR.Utils.foo(0, true)

Which brings me to structure because we just did a “require” statement. Corona likes to have a main.lua file running with every other file path relative to that. So, my “bin” folder looks something like this:

- bin/ - PR/ \*Utils.lua - Game/ \*World.lua \*Hero.lua \*main.lua

Because main.lua is the starting point for Corona, every require statement can be made relative to that, giving us simple statements like:

require("PR.Utils") require("Game.Hero")

Hope that helps!

@Abdou23

“what is the best way to structure a game with multiple levels?”

The best way to structure your project is in a way that works for you and fits your personal style.   However, beyond that ‘generic’ advice, these are all practices I use:

  • config.lua - Unless you’re very experienced and if you like knowing your design resolution, use a fixed design resolution instead of one of the ‘calculate best width/height’ approaches.
  • Use sub-folders for assets and scripts.  Nothing should live in the root folder except:
    • main.lua
    • config.lua
    • buid.settings
    • launch images
    • icons
    • everything else should be in sub-folders.
  • Use Modules for common code.
  • Use plugins and libraries when they save you effort and improve your project.
  • Do not assume you ‘must’ use compose scene manager.  You may very well be able to manage your own scenes.
  • If you use composer, use a fixed standard scene file layout and minimize the code in it.  Let the modules you write contain all of the app logic. i.e Don’t make 2000 line long ‘create()’ methods.

@Abdou23

You asked me to give more details on this statement:  " You can create ‘components’ using Lua."

As much as I wish I could give you a ‘simple example’, I cannot.  This is a very advanced topic.

Having said that, you  should feel free to dig through my old experimental behaviors code:

http://github.com/roaminggamer/SSKCorona/tree/master/ssk/behaviors

PS -

Neither Lua nor Corona has the concept of a ‘component’.  So there is no shortcut, “This is the right way, and only way, to design them.”  

Instead, you would design a component system based on your needs and understanding of Lua/Corona.  This is why it is advanced and why my experiment may not be grokable or useful to you.

Thanks a lot, you really are helping kickstart my  development with Corona, but still there are some issues that worries me about it, for example this sdk/framework/engine or whatever has been around for couple of years now, but still it lacks some basic features that is now standard in other engines, for example, Light effect, Particle systems, Wi-Fi testing(or even wired testing) I also noticed that the Composer GUI is currently suspended for some reason? I’m worried that devs. only maintain Corona and just make sure it only stays compatible with newer platforms OS releases without upgrading the SDK or it’s features, but perhaps I’m mistaken here. 

@Abdou23

I’m reading your post now, but I have a small request.  

Please use paragraphs with line breaks between them to help break up your posts.  I find them hard to read and while I want to help, I have only a little time to do so.  

Anything you can do to make it easier to help you… well I’m sure you get the idea.  Thanks!

Also try bullet list…

Example - Your post ‘re-edited’ for ease of reading…

Thanks a lot, you really are helping kickstart my  development with Corona, but still there are some issues that worry me about it.

For example this sdk/framework/engine or whatever has been around for couple of years now, but still it lacks some basic features that is now standard in other engines:

  1. Light effect,
  2. Particle systems,
  3. Wi-Fi testing(or even wired testing)

I also noticed that the Composer GUI is currently suspended for some reason?

I’m worried that devs. only maintain Corona and just make sure it only stays compatible with newer platforms OS releases without upgrading the SDK or it’s features, but perhaps I’m mistaken here. 

Answers to re-formatted question(s).

>> Part 1 - "sdk/framework/engine or whatever "

Corona is an SDK (read here for difference between an SDK and an Engine.)

In my opinion, SDKs are better than engines because:

  • an Engine may have more ‘features’, you are typically locked in to doing things a certain way, or into re-coding the engine.  
  • Whereas, an SDK may be missing a ‘feature’, but that feature can be easily added by using kit parts (elements of the SDK), or via 3rd party solutions.  

At the end of the day SDKs are more flexible and user friendly.

>> Part 2 the features you said are missing…

  1. Light Effect - I’m not sure what you mean by this…
  • Do you mean 3D lighting effects?  If so, then as this is as SDK for 2D games.
  • Do you mean calculated lighting?  If so, this is supported via shaders. (Links: 1, 2, 3, 4,  check them all and dig more from there.)
  • Is this a specific thing I (should but,) don’t know about?  If so, share some example links to this ‘Light System’
  1.  Particle Systems - This is supported a few ways: ( Built in libraries 1, 2;  3rd party solutions: CBE, Prism, Particle Candy.

  2. Wi-Fi Testing - Again, not sure what you mean here…

  • Can you test for a wifi connection?   No , but you can check for an internet connection and since  you don’t care if your connection is wired, wifi, or phone network (for the most part), that is enough.
  • Can you side-load apps to your device via WiFi?   Yes, but not as a feature of Corona.  This is a development environment feature you’ll have to work out on your own or as for help from someone on.  (Not me as I use wired side-loading.)
  • Can you modify your code locally (on PC/Mac) and have the app (nearly) instantly update on device for fast testing?   Yes , and this is a supported feature of Corona. 

Note: I took significant time and effort to answer this post, so I’d appreciate some info in return.  How are you learning to use Corona?

(I’m not picking on you here.  I want to understand your technique/approach so I can help better and so I can see where your friction points are.)

Specifically are you:

  • Reading the blogs, both old and new? Y/N
  • Searching the forms? Y/N
  • Reading the API Docs -  Y/N
  • Using Google to make searches like this?   Y/N
    • Corona SDK Particle System

PS - I used coloring in this post.  Generally that is frowned upon, but I did so because I wanted to be very clear and make the post easier to browse quickly for TL&DR folks.