Encapsulation ? OOP

Discussion and feedback on Construct 2

Post » Wed Sep 23, 2015 7:02 am

Will the day come when it is possible for a group of object to be grouped into a single object with it's own on start and update function ?
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Sep 23, 2015 8:50 am

hmm maybe I don't understand what you are looking for, but can't you pretty much do that using families?
Image
Get it on Google play or play on papio.nu
B
11
S
2
Posts: 79
Reputation: 786

Post » Wed Sep 23, 2015 10:54 am

Hello Kali,

No, Unfortunately that is not possible, imagine you have numerous grids that form a single entity and you have to duplicate that entity multiple times, with Object Orientated Programming, all you have to do is to make them all into a Single Class/Object and then just instantiate their single Object.

And with OOP, that object will have its own on create function ! :D
And its own Update function so that it will be able to take care of itself !
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Sep 23, 2015 11:15 am

Toddler wrote: imagine you have numerous grids that form a single entity and you have to duplicate that entity multiple times, with Object Orientated Programming, all you have to do is to make them all into a Single Class/Object and then just instantiate their single Object.


Isn't that what Containers do?
Placing objects in a container has the following effects:
If one object in a container is created, every other object in its container is also automatically created.
If one object in a container is destroyed, every other associated object in its container is also destroyed.
If a condition picks one object in a container, every other associated object in its container is also picked.


You have even some kind of constructor with 'On created'.
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Wed Sep 23, 2015 11:35 am

@Toddler, what exactly would you like to do in constructor and update functions?

It is true that in every OOP language you have a very useful constructor (and desctructor) function which is triggered when instance is being created, but in C2 you also have "Sprite -> On create" which is exactly the same.

I don't know what do you mean by "update" function, because there is no such thing in programming like a predefined "update" function. So I believe you need some custom actions here. This also can be easily done with Construct 2 functions. You can build your own function with parameters and set return value. You can also call it "update" ;). It is also worth to mention that you can call them with callbacks as well.

Regarding entities. You can set instance variables for your object, and their values might differ in each instance of your object so it is exactly like Class/Object in OOP.
ImageImage
B
27
S
16
G
69
Posts: 947
Reputation: 39,103

Post » Wed Sep 23, 2015 1:36 pm

Families and containers can help you achieve this but I admit it's not as practical as a "MovieClip" in Flash for exemple.
B
13
S
3
G
4
Posts: 70
Reputation: 3,451

Post » Wed Sep 23, 2015 4:28 pm

That name sounds real practical.

Anyway ops answer to the first post is the sdk allows for you to create that.
Image ImageImage
B
168
S
50
G
164
Posts: 8,239
Reputation: 105,597

Post » Thu Sep 24, 2015 8:35 am

Asmodean...YOU.....You are MY HERO!!!!!!! I am going to read up on Containers NOW!!!!!!!!!!!!

Mimiste, yes, I was thinking of movieclip in Flash ;p
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Thu Sep 24, 2015 9:29 am

Another tip if you want to go "OOP"-style ; I'd recommend having a "ClassInterface" Family that only adds a s_className to objects. You can then use Families as interfaces and use the s_className to call appropriate functions (e.g. "call FooIF.s_className + "BarMethod(uid, param1, param2)" ") implemented in the objects' relevant event sheets.

Therer no encapsulations, so it's all about working practices to keep things tidy really.

Think about how it was done in C to have a "OOP"-like structure, with custom typing mechanisms and emulated function tables.

I actually wanted to write an article about this ; if that's not sufficiently clear in this post, I should publish more details soon-ish
Image
B
23
S
9
Posts: 237
Reputation: 2,207

Post » Mon Sep 28, 2015 12:15 pm

I look forward to it.
B
12
S
3
Posts: 288
Reputation: 1,694


Return to Construct 2 General

Who is online

Users browsing this forum: JaredX, megatronx and 4 guests