Coming from Construct2, looking to acheve similar OOP featrs

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
keepee
Prole
Posts: 1
Joined: Sun Nov 23, 2014 10:14 am

Coming from Construct2, looking to acheve similar OOP featrs

Post 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!
User avatar
Reef
Prole
Posts: 33
Joined: Sun Mar 04, 2012 10:19 pm

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

Post 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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests