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
Thanks @ ArdentKid for this helpful tutorial. I also purchased already.
Just one question about this chunk …
function SceneGame:exitScene(event) --Clear all required files from lua's package.loaded game:dispatchEvent({name='onGameState', phase='exit'}) local pkgs = package.loaded for k,v in pairs(pkgs) do local test = string.find(k, 'Demos') if (test) then pkgs[k] = nil end end end
why do you search for the string ‘Demos’ ?
Haha woops! That’s for the ArdentKid mobile app I’m trying to release, which will allow this demo to be played inside the app, and project files to be purchased as an in-app purchase. Since I organized all the required files for the Demo in its own subfolder, I could easily un-require them by searching for the word, ‘Demo’. So this was to clean up the scene for the in-app demo. You could just replace it with the following:
local pkgs = package.loaded for k,v in pairs(pkgs) do local test = string.find(k, 'Classes') if (test) then pkgs[k] = nil end end
If all your code is in the “Classes” directory.
ah, ok. now it makes sense. thanks!
Thanks @ ArdentKid for this helpful tutorial. I also purchased already.
Just one question about this chunk …
function SceneGame:exitScene(event) --Clear all required files from lua's package.loaded game:dispatchEvent({name='onGameState', phase='exit'}) local pkgs = package.loaded for k,v in pairs(pkgs) do local test = string.find(k, 'Demos') if (test) then pkgs[k] = nil end end end
why do you search for the string ‘Demos’ ?
Haha woops! That’s for the ArdentKid mobile app I’m trying to release, which will allow this demo to be played inside the app, and project files to be purchased as an in-app purchase. Since I organized all the required files for the Demo in its own subfolder, I could easily un-require them by searching for the word, ‘Demo’. So this was to clean up the scene for the in-app demo. You could just replace it with the following:
local pkgs = package.loaded for k,v in pairs(pkgs) do local test = string.find(k, 'Classes') if (test) then pkgs[k] = nil end end
If all your code is in the “Classes” directory.
ah, ok. now it makes sense. thanks!
Hi I am really interested in buying the sample code to learn OOP quicker. But I need to know if there is any code in it that teaches how to “destroy” an object created from the class? I am pretty sure I can’t just do the below:
obj = mouse.new()
obj = nil
Because I will not be able to remove the image of the object right?
There is a common misconception about destroying objects. As I mention in my tutorial, you want to avoid the creation and destruction of objects during gameplay. Use pooling for efficient control over frame rates.
When changing scenes, Corona’s storyboard will handle all of the object destruction for you, assuming you use the methods in my guide (all custom listeners and objects should branch under the scene’s view).
The way my classes are set up, using “dispose” will pool the object (put it back on the shelf for later use). Hope that helps!
Thanks that helped. I have another question for you, why is scene on line 8 not local? I am abit confuse with the usage of it.
https://gist.github.com/ArdentKid/4958451#file-oop-scenegame-lua
On a side note, may I know what program you used to code lua?
I use Sublime Text 3 (beta). But 2 is just as good.
I use what I’ve defined as “scene” in the global scope for custom events. This is the best way for your classes to communicate with each other, as long as you localize it at the top of each class.
I see! Now it all make sense. One last curious question from me: Would it be better to “require storyboard” in every class than to use a global variable? If not, why?
Sorry for asking so much! Not doubting your skills but trying to understand the basics
Sure, you could do that. I haven’t tried it but I’d assume it returns the right table. Either way, it shouldn’t be too big of a concern since you’ll rarely make calls to it, (i.e. speed won’t be an issue).
Hi I am really interested in buying the sample code to learn OOP quicker. But I need to know if there is any code in it that teaches how to “destroy” an object created from the class? I am pretty sure I can’t just do the below:
obj = mouse.new()
obj = nil
Because I will not be able to remove the image of the object right?