Page 1 of 1

Coming from Construct2, looking to acheve similar OOP featrs

Posted: Tue Feb 10, 2015 10:15 am
by keepee
Hi all,

I'm hoping to port my game from C2 to Love2d and I've hit my first hurdle, it turns out there was a lot I was taking for granted in C2 in the way of 'stuff' management.

It would be awesome if someone with knowledge about C2 could help me draw the parallels between C2s OOP features and what those would be referred to as in lua/other languages... and ideally how to achieve those features in love2d. I was looking through some existing libraries 30log / middleclass / hump / mogamett etc. but idk what I'm doing really.

I wouldn't say I'm a newb to programming, but my knowledge is kind of deformed. C2 has many similarities but also big differences to standard programming. It's like coding with hand rails, but more advanced than something like stencyl. Here's C2s manual entry on objects if you're wondering how it works https://www.scirra.com/manual/68/objects

thanks in advance!

Re: Coming from Construct2, looking to acheve similar OOP fe

Posted: Wed Feb 11, 2015 4:01 am
by Reef
I'm sure others will be able to give you a better answer, but I will tell you what helped me.

First, lean how lua uses tables, they are a central part of the language and most OOP libraries you will find use metatables. They were confusing to me at first but Programming in Lua is a great resource http://www.lua.org/pil/contents.html. Second, you may not even need classes or OOP features for your game, you may not have considered this. Finally, I would suggest picking one of the libraries you listed and read the documentation and look at the source code; I tend to like kikito's approach to libraries and middleclass is very commonly used.

I'm still learning as well, but that's what I would suggest. I had to actually implement class inheritance with metatables myself before I really understood them. Now though, I would just grab a library if I felt like I needed anything beyond what a simple table could give me.

Re: Coming from Construct2, looking to acheve similar OOP fe

Posted: Wed Feb 11, 2015 9:53 am
by s-ol
Just from looking at the Object documentation you linked, I am pretty sure that a Construct "Object" is not an object in the sense of OOP. It is more like what other engines usually call "Entities" - a "game object" maybe.

There is no löve equivalent of this because löve is a toolkit and not an engine, defining stuff like that is your responsibility as a löve user (if you choose to. You usually don't need an equivalent like an entity class, you can handle all kinds of entities individually or set a "convention" for yourself, for example "everything has a :update(dt) and a :draw() method").

When you are looking at things like middleclass, those are OOP libraries, all the do is allow you to create OOP Objects (containers of data that are of a specified type/class) and classes ("plans" for the construction of an object / a collection of methods that each object can have).
Lua doesn't come with OOP on it's own and there are a million different ways of doing OOP with very different features (inheritance, multi-inheritance, class and instance variables and methods...). Most of these things are inventions if the C++ and Java world and basically useless in such a "loose" language as Lua. It is also the reason why there are so many class libraries, each has their own set of features (though many are similar here) and their own way of doing things.

I hope I could help :P