Instance Activation Advice (Parent Child?)

N

Necromedes

Guest
I'm trying to set up a text system for my game which allows the player to be within range of an instance, click on them and then the text box pops up.
I have that working but I need some advice/info on the parent/child subject.

I understand that a child object inherits all data from the parent object events unless another event of the same type exists in the child.

That being said, I need to be able to initialize certain variables in the create event to make this text system work properly (i,e include an array containing lines of dialogue, etc... for different npc's.)

So here in lies my question: If I make npc_bob be a child of npc_template and I have a create event in npc_template containing all of the system mechanics to make it work, am I able to include the create event text array in npc_bob without overwriting everything in npc_templates create event that would be inherited by npc_bob?

Thanks in advance.
 

Neptune

Member
Your children will not overwrite the parents. If you want to include a parent event (like the Create Event) in a child, use event_inherited() in the corresponding child's event(s) as needed (create, step, draw etc). If you inherit the Create Event it allows each child to have its own unique instance variables, and also inherit the parent's instance variables.

On a side note, parents are really useful for things like instance_position checks... If a child, of the parent your searching for, exists at the point -- it will return its ID!
 
put event_inherited() at the start of the child's creation event. That pulls all the data from whatever event it is in from the parent. You can add the same variables after in the child's event to overwrite the parents one if you want the variables to be different in one child. To make it clear:

Parent Create Event
Code:
hp = 10;
shield = 0;
Child Create Event
Code:
event_inherited();
shield = 10;
The Child object will end up with a hp variable equal to 10 and a shield variable equal to 10.
 
N

Necromedes

Guest
Excellent! This is going to make things so much easier for creating npc's.

Thanks a lot for the info!
 
Top