• 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 get instance ID of newly created instance and check if it exists?

N

Necromedes

Guest
Game Maker 1.4

I'm working on a side scrolling shooter and I'm creating a dreadnought that has turrets that the player must destroy. Upon doing so, the dreadnought is then destroyed as well.

The only way I can think of doing this is to store the instance ID's of the turrets after they're created by the dreadnought and check if they exist and when neither do, the dreadnought is destroyed.

My question is, what is the simplest way to do this? I've not worked on getting and storing instance ID's yet, so please try to keep the explanation easy to understand for me.

Thanks in advance.
 

CloseRange

Member
well how do you create the turrets?
lets say you have this in your dreadnought somewhere:
Code:
instance_create(x, y, obj_awesomeTurret);
change it to this:
Code:
var t = instance_create(x, y, obj_awesomeTurret);
t.parent = id;
you store the created turret in a variable.
then use that refrence to give it a variable (called parent) and set it to the dreadnaughts id (so we can look for it inside the turret)
in the turrets step event:
Code:
if(!instance_exists(parent)) instance_destroy();
 
N

Necromedes

Guest
Ah, I see. I'll give this a shot and see how it works, because that is indeed how I create my turrets.
 
Top