Encapsulation ? OOP

0 favourites
  • 10 posts
  • 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 ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • hmm maybe I don't understand what you are looking for, but can't you pretty much do that using families?

  • 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 !

    And its own Update function so that it will be able to take care of itself !

  • 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'.

  • 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.

  • Families and containers can help you achieve this but I admit it's not as practical as a "MovieClip" in Flash for exemple.

  • That name sounds real practical.

    Anyway ops answer to the first post is the sdk allows for you to create that.

  • 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

  • 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

  • I look forward to it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)