Destroying an object if another object is destroyed

C

Conor Egan

Guest
Hello. I am fairly new so I'm sorry if this is a stupid question.
I have two objects relating to the same enemy, and I want it to be so that when object1 gets destroyed (which happens when its hp equals 0) object2 will get destroyed as well, but I can't quite figure out how. I though of using instance_exists, but from what I can tell I can only figure out how to make that check if an object exists, not if one doesn't exist.
Thanks for any and all help
<3
 

TheouAegis

Member
If object B's existence is dependent upon object A's existence, then have object A create object B and save object B's id in a variable. Then in object A's destroy event have it destroy object B.

object1 Create Event or whatever:
contingent = instance_create(x,y,object2);

object1 Destroy Event:
with contingent instance_destroy();


If however there will be multiple object Bs in the room all contingent upon object A, then just specify the object instead of saving the id.

object1 Destroy Event:
with object2 instance_destroy();


If however there are multiple object Bs in the room but only those created by object A will be destroyed, save their IDs in a ds_stack and then pop the stack to destroy the instances.


object1 Create Event:
stack = ds_stack_create();

object1 Create Event or whatever:
ds_stack_push(stack, instance_create(x,y,object2);

object1 Destroy Event:
while ds_stack_size(stack) > 0
with ds_stack_pop(stack) instance_destroy();
 
Last edited:
C

Conor Egan

Guest
If object B's existence is dependent upon object A's existence, then have object A create object B and save object B's id in a variable. Then in object A's destroy event have it destroy object B.

object1 Create Event or whatever:
contingent = instance_create(x,y,object2);

object1 Destroy Event:
with contingent instance_destroy();


If however there will be multiple object Bs in the room all contingent upon object A, then just specify the object instead of saving the id.

object1 Destroy Event:
with object2 instance_destroy();


If however there are multiple object Bs in the room but only those created by object A will be destroyed, save their IDs in a ds_stack and then pop the stack to destroy the instances.


object1 Create Event:
stack = ds_stack_create();

object1 Create Event or whatever:
ds_stack_push(stack, instance_create(x,y,object2);

object1 Destroy Event:
while ds_stack_size(stack) > 0
with ds_stack_pop(stack) instance_destroy();
thank you so much!
 
Top