1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Multiple Inheritance, event_perform_object trick, but with Variable Definitions in 'Parent' objectS?

Discussion in 'Programming' started by Niall Edwards, Nov 8, 2019.

  1. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    14
    OK, forgive me as I am new to GameMaker Studio 2 and the forums so I hope people understand what I am getting at.

    Firstly, imagine the wonderful Variable Definitions option on Objects did not exist.

    I had been using event_perform_object 'trick' to pull down clusters of variables from multiple 'parent' objects into a 'child' object, overriding values at the child object level, and on from there. Thus, lovely multiple inheritance. Of course, I had been setting out those various variables in the multiple 'parent' objects in the Create event Action, not the Variable Definitions.... hmmmm.

    Then I started to wonder.

    Could I rather set out those same 'parent' object variables in the 'parent' object 'Variable Definitions' area instead of the Create event Actions of the 'parent' object?

    Here is the question though --- If I did that, which would otherwise be preferable, could I though 'inherit' those variables into a child object using the event_perform_object trick I had been using before? If so what event on a 'parent' object would I be calling from the Create event Action in the 'child' object? Indeed, with the 'parent' object, what is the event I would be calling to inherit variables if the variables are created in Variable Definitions and not in the Create event Action?

    [edit] Also, can I set up a variable in the Create event Action AND also set up the very same variable in Variable Definitions? It's a massive effort, but, if possible, would this be a way around the above?

    I really hope I am explaining myself enough here - probably not! As I say, I am new to GMS2.....
     
    Last edited: Nov 8, 2019
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,607
    I don't think that's supported at the moment. The best approximation I know of is copying in the variable definition values one-time from non-immediate parents and using that as an override, but that won't sync automatically the way it can with the immediate parent.
     
    Niall Edwards likes this.
  3. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    14
    @FrostyCat ,. Thanks for the response. I guess I am going to have to go with old school approach then if no-one has any other thoughts...
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,867
    You could mimic aspect-oriented programming by having "init" scripts that create instance variables (not vars, lingering variables), it works well as long as you don't rely on is_ancestor() and automatic event inheritance. And if you have only chained parenting (and not "trees" of parents), event_inherited() chains as well (if parent runs grandparent's inherited event this way and child runs parent's, the child will run both the grandparent's event and its parent's event. event_inherited() rocks when used correctly)
     
  5. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    14
    @Yal , thanks for the pointers...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice