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

How to override parent create event

F

fastermastercaster

Guest
So very simple issue thats more of a coding pet peve than anything. Basically the parent of an object has creation code that is semi long and nothing needs to be changed except for a few variables. So when the child has a create event with "event inherited" even when the code after sets the variable to something different, it doesnt inherit it. Which forces me to copy the create event code in the parent and paste it into all the children only changing 1 variable. i cant remove the variable in the parent object or it crashes. so i need to "override" the parents variable in the child. gamemaker doesnt do this automatically and just ignores the child create event as if its not there. the manual page on event_inherited shows an example of a switch statement doing this exact thing but the issue is i dont need a switch statement here, just setting the variable, and i have no if statement to use because its not depending on anything, i just need it to be set when created.

TL;DR

Parent create event

Blah = 0;
//other variables and stuff


child create event

event inherited();
Blah = 1;


Output: everything is inherited in the child and blah = 0. i just need blah = 1
 
The child-parent relationship should work the way you described it.

In the child, you call event_inherited() at the start of the Event. This will run the parents Create Event, thereby associating all the parents Create Event code with the child. At this point, the child should have all the same variables defined as the parent.

Then, the rest of the child Create Event runs. In this case, you have Blah = 1. By the end of the childs Create Event, Blah should equal 1.

Perhaps you could list the full PArent and Child Create Event code, as well as showing the code where you actually create the child instance calling instance_create_*

Also what version of GameMaker are you using?
 

sylvain_l

Member
Silly question how do you check the value of blah ? Because if you check it with a show_debug_message() in the parent create event logically blah = 0 for both at the time of the debug message
 
F

fastermastercaster

Guest
The child-parent relationship should work the way you described it.

In the child, you call event_inherited() at the start of the Event. This will run the parents Create Event, thereby associating all the parents Create Event code with the child. At this point, the child should have all the same variables defined as the parent.

Then, the rest of the child Create Event runs. In this case, you have Blah = 1. By the end of the childs Create Event, Blah should equal 1.

Perhaps you could list the full PArent and Child Create Event code, as well as showing the code where you actually create the child instance calling instance_create_*

Also what version of GameMaker are you using?
Thats what i thought so i looked through it and found the issue. In the parent create event the variable being set (example here of blah) was a debug sprite and the children have their final sprites. It turns out they were still showing the debug sprite because sprite_index = blah was ONLY at the end of the parent create event and not in the child so even though it was being changed, the changes were not "applied"... i feel dumb haha. thank you for the response and helping me!
 
F

fastermastercaster

Guest
Silly question how do you check the value of blah ? Because if you check it with a show_debug_message() in the parent create event logically blah = 0 for both at the time of the debug message
the variable was for the sprite_index so i thought i didnt need to in order to see the changes but apparently i was wrong per the response above. This was part of what helped solve it so thank you! from now on im gonna have to debug like that even when i think its not necessary.
 
Top