Object-Oriented Lua Tutorials

Hello ArdentKid,

Thank you for being so thorough with updating your tutorials to help us too. I did realize some time ago when I was trying to implement inheritance with your framework, that your former approach was not exactly OO but I do think that for simpler, less inheritance-intensive purposes it is still a valid approach.

I do wonder one thing in your revised tutorials.

In your subclasses Animal and Cat, near the beginning of their scripts, you are creating a local variable “Super” into which you load the respective super class script. You then reference this local variable whenever you need to access parent variables/methods.

Is that local "Super"variable not redundant? I thought that the call Class([parentClass]) took care of creating a “super” variable that directed to the parent class.

Is there any particular reason why you are creating this local “Super” variable in each subclass?

Thank you for your continued help! [import]uid: 142439 topic_id: 33679 reply_id: 143141[/import]

@Ardenkid: thank you so much for the re-write! Beautiful. One suggestion about the full example. Rather than counting on people donation, I will strongly suggest your make the example paid. Say $10-20 and have people who really want to start using OOP to pay for it.

Of course just a suggestion. Maybe other people would have better suggestions to make writing a full example worth your time.

Mo [import]uid: 100814 topic_id: 33679 reply_id: 143152[/import]

@rcuba87 - you can just put the super class’s require in the class call: Class(require(“someParentClass”)), but then make sure you replace all your calls to the super class with for example “self.super.show(self)” instead of just “Super.show(self)”. I like the the second one better syntactically, so thats why I localize it.

@LaridGames - thats a good idea but Im not sure how many people would buy it. Its still a good recommendation so im leaning that way now. Thanks! [import]uid: 36792 topic_id: 33679 reply_id: 143207[/import]

Hey All,

The re-write of this tutorial is finally complete! I mashed them up into one definitive guide. Enjoy!

http://www.ardentkid.com/blog/from-zero-to-oo-ardentkids-guide-to-object-oriented-lua-with-corona-sdk [import]uid: 36792 topic_id: 33679 reply_id: 142875[/import]

Nice! I’ll suggest it to be included to the resource centers:

http://www.coronalabs.com/resources/tutorials/

http://developer.coronalabs.com/forum/2013/01/07/corona-resource-centre-tutorials-templates-and-more

Naomi [import]uid: 67217 topic_id: 33679 reply_id: 142884[/import]

Thanks Naomi! [import]uid: 36792 topic_id: 33679 reply_id: 142886[/import]

Hello ArdentKid,

Thank you for being so thorough with updating your tutorials to help us too. I did realize some time ago when I was trying to implement inheritance with your framework, that your former approach was not exactly OO but I do think that for simpler, less inheritance-intensive purposes it is still a valid approach.

I do wonder one thing in your revised tutorials.

In your subclasses Animal and Cat, near the beginning of their scripts, you are creating a local variable “Super” into which you load the respective super class script. You then reference this local variable whenever you need to access parent variables/methods.

Is that local "Super"variable not redundant? I thought that the call Class([parentClass]) took care of creating a “super” variable that directed to the parent class.

Is there any particular reason why you are creating this local “Super” variable in each subclass?

Thank you for your continued help! [import]uid: 142439 topic_id: 33679 reply_id: 143141[/import]

@Ardenkid: thank you so much for the re-write! Beautiful. One suggestion about the full example. Rather than counting on people donation, I will strongly suggest your make the example paid. Say $10-20 and have people who really want to start using OOP to pay for it.

Of course just a suggestion. Maybe other people would have better suggestions to make writing a full example worth your time.

Mo [import]uid: 100814 topic_id: 33679 reply_id: 143152[/import]

@rcuba87 - you can just put the super class’s require in the class call: Class(require(“someParentClass”)), but then make sure you replace all your calls to the super class with for example “self.super.show(self)” instead of just “Super.show(self)”. I like the the second one better syntactically, so thats why I localize it.

@LaridGames - thats a good idea but Im not sure how many people would buy it. Its still a good recommendation so im leaning that way now. Thanks! [import]uid: 36792 topic_id: 33679 reply_id: 143207[/import]

Hey! I just saw that you have a sample app using your OOP approach. That’s a fantastic news! I am very curious how complex is the code un term of say physics and collision for instance? Does the sample code deals with those type of things? I am very curious on the list of classes that are used and their structures. Can you talk about that? Finally, any chance for a limited time price break? :slight_smile: Thanks again. Mo

Hi LaridGames,

The sample code does not use corona’s box2d, because it is not a physics-based example. Instead, it uses efficient point-based collision detection. The classes are everything mentioned in the tutorial, along with pause/ resume, and whatever else is mentioned on the page as advertised. Sorry, the price is what it is for now, and I think it’s very reasonably priced for the things I’ve demonstrated :slight_smile:

Cool! Thanks a lot. Mo

Hi, I went ahead and got the source code and I have to admit I am very excited to look into it and learn how to develop in a more OOP way (if that make sense!) After a quick look I also have to admit it is a little overwhelming! I am sure with your online tutorial and the source code, I will eventually get it. To speed up that understanding I will love 2 things if at all possible: - a little more comments in the source code OR maybe a short working document that would quickly show how the pieces works together? Not about the OOP in general (I think you online tutorial works great for that!) I am talking about the actual game of cat in mouse. I am trying to put my head around it and like I said it is little overwhelming at first. - Another thing I am curious about is how to integrate physics into the game (not really for this game but for future game i would mske using OOP) For instance let say I needed to make the mouse a physic object? How can I go about doing that? In any event, I am very grateful that you decided to make this source code available to us. As you know from my earlier posts, that I have been waiting for this example for a long time! I also understand that time is a limited commodity so I am not looking for something right away but maybe in a future update. For people new to OOP (like me!) who bought the code I think it will help us speed our learning curve! Thanks again. Mo

Thanks & you’re welcome, I’m glad it’s helping!

I will spend some time in updating the comments and code a bit (someone else requested sounds as well), and you’ll receive an email with the updates. I never really used corona’s physics library because I haven’t created any physics-based games, but that stuff isn’t necessary for OOP, and I don’t want to bloat the scope of the tutorial. I would continue with these tutorials and other specific subjects when I find the time, but probably not any time soon. I will also make a private git repo for this project so that you and others can contribute to making it better as well.

Cool, thanks ArdentKid! Yea I will not worry to much about the physics part. As you said it is not really  a OOP issue.

 On the other hand, I cannot really tell you how I will appreciate more details or comments on the code itself as it stands right now. I spent pretty much the all day today going line by line to see if I can make sense and because I am new to OOP, it is a tough going!

So yes more comments in the source code will be much appreciated.The tutorial really helps. Still they are many places that I have problems with (again because it is so new to me) and love to have more details on some lines in your source code. I am wondering what will be the best way to do this. Obviously since you are selling the source code, I do not want to display it here! I would like to go from module to module (sorry class to class!) and mark where I have difficulty understand why you are doing it that way (usually it is only 1 or 2 lines that are causing me problems).

Is sending a support email the best way? Or doing it in this form but only showing the class name and code line number?

I am very excited about using your OOP methodology on my next app but it is clear that I need first to understand you source code better.

Please let me know.

Thanks.

Mo  

Yes, please reply to the email for support. I will do my best to help if it’s a simple question, but I also offer tutoring services if you’d like to discuss things in-depth.

Excellent! I will send you an email with some questions about the code as soon as I am done with the review of the code. I will try not to ask stupid questions…I cannot make any promises here:)

Thanks,

Mo

Hi Omid,

Your Mouse Run demo has been very helpful in getting up and running with OOP in Lua for Corona SDK. I’m new to Corona and Lua, but have many years of experience in C# development for web and windows applications.  I am currently in the design phase of my first Corona app.  I’d like to have my code modular so I can re-use in future projects.  I found many examples of OOP in Lua and was not sure which approach to take.  Yours seemed the most straight forward with detailed explanations of the OOP concepts in Lua and of course it is geared towards development in Corona SDK.

One thing I noticed while reviewing your demo is that there is a Sound.lua class file but there is no implementation or usage of sounds in your demo.  Is it possible for you to update your demo with some basic sound implementations?  I would really appreciate it.

Thanks,
Will

Hey! I just saw that you have a sample app using your OOP approach. That’s a fantastic news! I am very curious how complex is the code un term of say physics and collision for instance? Does the sample code deals with those type of things? I am very curious on the list of classes that are used and their structures. Can you talk about that? Finally, any chance for a limited time price break? :slight_smile: Thanks again. Mo

Hi LaridGames,

The sample code does not use corona’s box2d, because it is not a physics-based example. Instead, it uses efficient point-based collision detection. The classes are everything mentioned in the tutorial, along with pause/ resume, and whatever else is mentioned on the page as advertised. Sorry, the price is what it is for now, and I think it’s very reasonably priced for the things I’ve demonstrated :slight_smile: