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

Child Instance Destroy When Parent Instance Destroyed?

A

Anomaly

Guest
I'm working on a new project idea with a limited number of instances off an object at any given time (3).

Each of those have 1 separate object instance that they create.

All these pairs are the same.
So there's 3 pairs of object instances "allowed"
No more than 3 pairs can be existing.
Some can be destroyed, but only 3 pairs should ever exist at one time.

When I destroy the first "parent" instance,
I need it's "child" to be destroyed as well.
This is the big problem.

I've tried a multitude of methods and know I have to use id's but I am having a very hard time working it out.

NOTE: There's nothing using the "parent" option in the object properties here.

Any help would be great.

Thanks!
 

Perseus

Not Medusa
Forum Staff
Moderator
Each of those have 1 separate object instance that they create.
Couldn't you store the instance id which is returned by the instance_create() call in a variable? In the "parent" object's Destroy event, you could destroy the instance whose id has been stored in the said variable. Something like this:
Code:
// Create
my_child = instance_create(x, y, obj_Child);

// Destroy
with (my_child) {
    instance_destroy();
}
 
A

Anomaly

Guest
right.. been trying that.. alot..
just can't seem to get the variable to do what you're saying while i do what i'm also doing with the angle and direction...

im using a with when i create it.
Code:
with (instance_create_layer(x,y, "Things", oThingBig))
            {
                direction = other.image_angle;
                image_angle = direction;
                        }
how can i combine the two?
 
D

dannyjenn

Guest
Do it like this:
Code:
child = instance_create_layer(x,y, "Things", oThingBig);
with(child){
    direction = other.image_angle;
    image_angle = direction;
}
Alternatively, I think that this would work too:
Code:
with(instance_create_layer(x,y, "Things", oThingBig)){
    direction = other.image_angle;
    image_angle = direction;
    other.child = id;
}
 
A

Anomaly

Guest
i got it working using a global variable passed on...
but i'm going to try your ideas also thank you guys
 
A

Anomaly

Guest
Do it like this:
Code:
child = instance_create_layer(x,y, "Things", oThingBig);
with(child){
    direction = other.image_angle;
    image_angle = direction;
}
Alternatively, I think that this would work too:
Code:
with(instance_create_layer(x,y, "Things", oThingBig)){
    direction = other.image_angle;
    image_angle = direction;
    other.child = id;
}

yeah perfect.
always in the details and formatting i get hung up on.. thanks a ton!
 
Top