• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Inheritance and GML

I don't understand the events in GML. with regards to inheritance.
Please tell me where I'm going wrong.

There is the object window and on the object window. You have events and parents.

I want to I have a parent and children and an object. Where do I place the children?
At the bottom? And if I want to do any collisions between the children and the objects
in the events box how would I do that?

I tried flipping the content between the children and events but didn't get much
luck. I appreciate your help.
 

NightFrost

Member
GMS parenting is primarily about code inheritance. When you set an object as child of another object, it inherits all the events you have created in the parent. You can manually override the inheritance to extend the event code, in which case you must put event_inherited() into the child object's event to inherit the parent's code for that event.

Additionally, collision detection can refer to all instances of all child objects (and the parent, if any instances exist for that) at the same time by using the parent object name.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Inheritance works from top to bottom. Parents are at the top, children are at the bottom.

Children have all the events their parents have, unless the child also has that event. Then the event's code is only executed when the child calls event_inherited.

All children are considered to be instances of the parent, but not vice-versa. All apples are fruit, but not all fruits are apples.
 
Ok. I glossed over the manual section pretty well. I think I learned this in Object Oriented I. Just some details that are unique to GML I think that that's where I'm stuck

So GML has inheritance, polymorphism, encapsulation, abstraction?


So @chamaeleon can you tell me if this looks right?

BatParentObject

A whole lot of FranksParents
A lot of BOSSESParents
A lot of BrainParentObjecs
A lot of SpecialBrains

So all four of the in are in an umbrella: BrainSuperParent. object

And each FrankParents, BOSSESParents, BrainPraentObject, and SpecialBrains are under a umprella for individual objects.
 
Last edited:

Nidoking

Member
It has all of those things if you use it properly. I'm told that using objects in Game Maker is WRONG, all-caps WRONG, but I don't believe it for a minute.

Perhaps it would help if you explained a specific thing that you're trying to do and can't figure out, instead of trying to piece together a bunch of general information.
 

chamaeleon

Member
Ok. I glossed over the manual section pretty well. I think I learned this in Object Oriented I. Just some details that are unique to GML I think that that's where I'm stuck

So GML has inheritance, polymorphism, encapsulation, abstraction?
GML, the language, has just about nothing of this nature (not counting implementing your own to some extent). Using GMS, the game making platform, and its object hierarchy, you get some of this, in a poor man's fashion. Once GMS 2.3 is released one can say that GML support these things using structs.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I'm told that using objects in Game Maker is WRONG, all-caps WRONG, but I don't believe it for a minute.
Lol! I don't know who told you that, but they are WRONG, all caps WRONG! :p I mean, why does GM have objects if it's not for them to be used? Sure, you can write a whole menu system in a single script and call it from a single object... or instead you can create a controller object and objects for each of the buttons, and use parenting so each button inherits most of the events from the parent and you only need to override ro add to those that each button requires, or even use a user event! Which is easier to maintain? Which is more obvious? I'll go with having 20 named button objects over a massive script that takes five minutes to scroll through every time I need to add a new menu item or change a value!

The great thing about GM is there are multiple ways to achieve the same thing, and none of them are "right" or WRONG. If it works it works!
 
I mean, why does GM have objects if it's not for them to be used? Sure, you can write a whole menu system in a single script and call it from a single object... or instead you can create a controller object and objects for each of the buttons, and use parenting so each button inherits most of the events from the parent and you only need to override ro add to those that each button requires, or even use a user event!
My impression of OO in GML is it is that it is a hybrid language and can do the full effect that an enterprise language can. If you look at computer science theory GML has all the components that are necessary to be considered to be a full fledge language. But that's like comparing assembly language and Visual Basic. You can do it with either but one way is easier than the other.
 

TsukaYuriko

☄️
Forum Staff
Moderator
This is a forum, not a chat. Delayed conversation is the standard here. ;)

That aside, I couldn't really find a question in your previous post - so unless you have any further, yeah, we're done with this topic.
 
This is a forum, not a chat. Delayed conversation is the standard here.
I just wondered. There was a steady stream of messages then everyone just stopped it. lol./

I'm still not 100% on how the mechanism works. The object can have events and parents.
So if I create collision events for the object. to collide to say, WindBatObject , against
a BrainSuperParent. An BrainSuperParent is an umbrella term for a bunch of brains.

Would this work?
 

Evanski

Raccoon Lord
Forum Staff
Moderator
I just wondered. There was a steady stream of messages then everyone just stopped it. lol./

I'm still not 100% on how the mechanism works. The object can have events and parents.
So if I create collision events for the object. to collide to say, WindBatObject , against
a BrainSuperParent. An BrainSuperParent is an umbrella term for a bunch of brains.

Would this work?
obj_bob has a collision event keeping it from touching obj_sally

obj_chad is a child of bob so he has the collision event as well, no need to edit chad to make him act like bob around sally

but obj_simp is a child of bob as well but we gave him his own collision code with sally, so now he isnt doing anything bob says to do with sally

however obj_whiteknight is also one of bobs kids and his collision code with sally is in fact his own, but he has event_inherited as his first line so he takes what bob says into consideration before doing his own thing with sally
 

TsukaYuriko

☄️
Forum Staff
Moderator
I just wondered. There was a steady stream of messages then everyone just stopped it. lol./

I'm still not 100% on how the mechanism works. The object can have events and parents.
So if I create collision events for the object. to collide to say, WindBatObject , against
a BrainSuperParent. An BrainSuperParent is an umbrella term for a bunch of brains.

Would this work?
Yes. As in, any child of BrainSuperParent will collide with WindBatObject, or WindBatObject will collide with any child of BrainSuperParent.
 

Yal

🐧 *penguin noises*
GMC Elder
Ok. I glossed over the manual section pretty well. I think I learned this in Object Oriented I. Just some details that are unique to GML I think that that's where I'm stuck

So GML has inheritance, polymorphism, encapsulation, abstraction?
You shouldn't throw around buzzwords when you're still clearly not sure how the core concepts work 🦈

In GM, a child object is treated as a special case of its parent. Loops and collision events with a parent will trigger on any of its descendants as well.
Child objects will, when they have empty events, execute the event of their most immediate ancestor (that has code in that event). If they have their own code in an event, they override that event and will only execute their own code. (event_inherited lets you explicitly use your most immediate parent's code for an event, if you want both custom and inherited code)

But to answer your question...
  • Inheritance: handled via parenting wholesale.
  • Polymorphism: handled implicitly (children are included in loops over their ancestors)
  • Encapsulation: can be handled via event_inherited / event_perform_object.
  • Abstraction: GM is completely built around this.
 
You shouldn't throw around buzzwords when you're still clearly not sure how the core concepts work 🦈

In GM, a child object is treated as a special case of its parent. Loops and collision events with a parent will trigger on any of its descendants as well.
Child objects will, when they have empty events, execute the event of their most immediate ancestor (that has code in that event). If they have their own code in an event, they override that event and will only execute their own code. (event_inherited lets you explicitly use your most immediate parent's code for an event, if you want both custom and inherited code)

But to answer your question...
  • Inheritance: handled via parenting wholesale.
  • Polymorphism: handled implicitly (children are included in loops over their ancestors)
  • Encapsulation: can be handled via event_inherited / event_perform_object.
  • Abstraction: GM is completely built around this.
You shouldn't throw around buzzwords when you're still clearly not sure how the core concepts work 🦈
I know how those core concepts work. I just don't know how they are implemented in GML. Its exactly like switching languages.
I'm exceptional in Java and C. But doing the same code in say, Python, I might have trouble.
 
Top