Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Solved] Game Maker inheritance complications  (Read 9084 times)

0 Members and 1 Guest are viewing this topic.
[Solved] Game Maker inheritance complications
« on: November 13, 2010, 10:35:07 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I have a simple question about inheritance in Game Maker. I know that if an event is defined in a child it overrides the event defined in the parent. However when you use event_inherited you can execute the code in the parent. Or at least it should be.

I am trying to do this with the Create however. I seem to fail, because variables defined in the parent are not usable in the child. Is this correct and thus do I need to define each variable in the child again or is there a way around it.

Really Game Maker's inheritance is a big pain in the ass.
« Last Edit: November 14, 2010, 09:46:31 am by Niek »
Logged
Re: Game Maker inheritance complications
« Reply #1 on: November 13, 2010, 10:55:05 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
That is very odd, I have done the same exact thing, and I don't have the problem you described.
Logged
  • Pyxosoft
Re: Game Maker inheritance complications
« Reply #2 on: November 13, 2010, 11:39:39 pm »
  • Mr. Pixel
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 245
Thanks to you, I learned today something new about parent and child objects. I always thought child object overrides parents events and this can't be avoided.
« Last Edit: November 13, 2010, 11:43:07 pm by drandula »
Logged
Re: Game Maker inheritance complications
« Reply #3 on: November 13, 2010, 11:41:03 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 616
I am trying to do this with the Create however. I seem to fail, because variables defined in the parent are not usable in the child. Is this correct and thus do I need to define each variable in the child again or is there a way around it.

Really Game Maker's inheritance is a big pain in the ass.

No that should not be the case.  I have done that many times throughout my games and it works fine every time.  There must be something else wrong.  It should create all of the variables if you put the event_inherited() in the creation event of the child object.

edit:  That is if you even have a create event in your child object...  If you don't then you shouldn't have to do anything.

Really Game Maker's inheritance is a big pain in the ass.

I haven't had that many problems with it...  My only wish is that you could assign more than one parent object.
« Last Edit: November 13, 2010, 11:48:55 pm by Aero88 »
Logged

Mamoruanime

@Mamoruanime
Re: Game Maker inheritance complications
« Reply #4 on: November 14, 2010, 01:08:40 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
My only wish is that you could assign more than one parent object.

I... don't think that's normal in any language o.0;; I think you'd go about that by having your parent object a child of yet another object.
Logged
Re: Game Maker inheritance complications
« Reply #5 on: November 14, 2010, 01:17:24 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
Multiple inheritance is supported in c++. I remember being bummed when c# didn't support it. (Before realizing it was a good thing)
Logged
  • Pyxosoft

Mamoruanime

@Mamoruanime
Re: Game Maker inheritance complications
« Reply #6 on: November 14, 2010, 01:31:54 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
Oh o.0

Yeah that seems really odd to me... What would be the purpose for that?
Logged
Re: Game Maker inheritance complications
« Reply #7 on: November 14, 2010, 05:56:17 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
Multiple inheritance is supported in c++. I remember being bummed when c# didn't support it. (Before realizing it was a good thing)
How is that a good thing exactly? I haven't messed around with inheritance very much (mainly different varieties of enemies and items).
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.
Re: Game Maker inheritance complications
« Reply #8 on: November 14, 2010, 06:19:09 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
I just mean that c# technically doesn't support multiple inheritance. (Although you can chain inheritances) Here's some criticisms towards Multiple inheritance: http://en.wikipedia.org/wiki/Multiple_inheritance#Criticisms

I tend to use inheritance as a way to generally group objects, and inherit from previous base types to add on to them, or override behaviors to solve a new problem.
Logged
  • Pyxosoft
Re: Game Maker inheritance complications
« Reply #9 on: November 14, 2010, 06:36:06 am »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 616
My only wish is that you could assign more than one parent object.

I... don't think that's normal in any language o.0;; I think you'd go about that by having your parent object a child of yet another object.

Yeah in most cases that is true, however I have come across a number of situations that it would have been convenient for, though nothing is coming to mind at the moment...  With GM though your are stuck with having to deal with it by creating Parent trees as you said.

edit: I guess multiple inheritances is supported in C++ as Xfixium stated, though I don't have experience with it...  Either way I guess it is probably not a recommended way of coding for the reasons Xfixium mentioned.  Unfortunately most of my coding experience comes from GM which I hear is quite different than most codes.
« Last Edit: November 14, 2010, 06:43:44 am by Aero88 »
Logged
Re: Game Maker inheritance complications
« Reply #10 on: November 14, 2010, 06:58:52 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Multiple inheritance is actually a dangerous thing, as it can make an object's behaviour unpredictable. Having the same methods with the same signature defined in more parents makes things unpredictable, as it is difficult to know for the compiler to assign which behaviour to the child. In C++ it is recommended that you only use multiple inheritance when you are a really really really really really skilled C++ programmer.

Java also has only one parent object a child can inherit from. But they made a work around for it in the form of Interfaces "Objects without methods defined, only declared."

In GM that same problem arises when you use event_inherited. If more than one parent has a behavior for that event defined either through its parent or by itself. Then the GM compiler would not know which behavior is executed.

Weird that my problem does not happen with some one else. Maybe it is the how variables are declared.


EDIT: Okay thnx to Xfixium the problem is solved. I feel like a major idiot and n00b for making such a basic mistake. Forgetting to include event_inherited in the last child of the chain and not even seeing it when I go over it a million times.

*** Leaves to sit in the corner with a Dunce hat on. ***
« Last Edit: November 14, 2010, 09:45:45 am by Niek »
Logged
Re: Game Maker inheritance complications
« Reply #11 on: November 14, 2010, 04:50:06 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 616
In GM that same problem arises when you use event_inherited. If more than one parent has a behavior for that event defined either through its parent or by itself. Then the GM compiler would not know which behavior is executed.

Glad you got it figured out...  Actually though, I believe that in game maker event_inherited() simply executes the events of the nearest ancestor that has a behavior for the given event.  So if you want it to go back further than that, then that ancestor must have event_inherited() in the given events actions list.

edit: by nearest ancestor I mean by lineage, not by position of course.
Logged
Re: Game Maker inheritance complications
« Reply #12 on: November 14, 2010, 05:13:52 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
In GM that same problem arises when you use event_inherited. If more than one parent has a behavior for that event defined either through its parent or by itself. Then the GM compiler would not know which behavior is executed.

Glad you got it figured out...  Actually though, I believe that in game maker event_inherited() simply executes the events of the nearest ancestor that has a behavior for the given event.  So if you want it to go back further than that, then that ancestor must have event_inherited() in the given events actions list.

edit: by nearest ancestor I mean by lineage, not by position of course.
And you are completely correct. But if two or more parents are equally near than there would be a problem. That is why GM only allows a maximum of 1 parent per object, unlike C++ that allows for more than 1 parent.
Logged
Re: Game Maker inheritance complications
« Reply #13 on: November 14, 2010, 05:37:08 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 616
In GM that same problem arises when you use event_inherited. If more than one parent has a behavior for that event defined either through its parent or by itself. Then the GM compiler would not know which behavior is executed.

Glad you got it figured out...  Actually though, I believe that in game maker event_inherited() simply executes the events of the nearest ancestor that has a behavior for the given event.  So if you want it to go back further than that, then that ancestor must have event_inherited() in the given events actions list.

edit: by nearest ancestor I mean by lineage, not by position of course.
And you are completely correct. But if two or more parents are equally near than there would be a problem. That is why GM only allows a maximum of 1 parent per object, unlike C++ that allows for more than 1 parent.

Ah I see.  I was misunderstanding you.  I thought you were saying that GM has that problem, not that it would have that problem if multiple parents were permitted.  Yes you would have to be careful if that were the case, which is why they do not allow it in GM.  I am on board with you now.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.041 seconds with 62 queries.