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

Check if instance exists, not child object?

W

wkaudio

Guest
I have a controller object that is always checking of a player object exists. If it does not, it creates one after a slight delay.
I recently added a powerup to my game that creates duplicate players (obj_dupplayer). I took away most of their code but have run into an issue where if an obj_dupplayer exists, it will assume an obj_player exists, because it is the dupplayer’s parent.

How can I check if obj_player exists, not counting obi_dupplayer?

Thanks!
 

FrostyCat

Redemption Seeker
If existence is the only thing you'll ever check, you can get away with this for now:
Code:
if (instance_number(obj_player)-instance_number(obj_dupplayer) > 0)
But if you'll be checking for anything more detailed, you should reorder your object hierarchy instead of expecting a defective hierarchy to be accommodated with some magical syntax. It's not the first time I had to stress this. If A should not count as an example of B, then A should not be a child of B.
 
Last edited:
B

Bayesian

Guest
You should have one main parent and make it have two children. One of them is the player one is the duplicated player. That way you can search for them separately and you can use the main parent to find them all.
 
W

wkaudio

Guest
If existence is the only thing you'll ever check, you can get away with this for now:
Code:
if (instance_number(obj_player)-instance_number(obj_dupplayer) > 0)
But if you'll be checking for anything more detailed, you should reorder your object hierarchy instead of expecting a defective hierarchy to be accommodated with some magical syntax. It's not the first time I had to stress this. If A should not count as an example of B, then A should not be a child of B.
Thanks for the reply. I'm very aware of the idea that if A should not be B, B should not be A, I just added this powerup very late in my game's development and this was an oversight on my end. Existence was the only thing I had to check, however at the beginning there are 0 obj_players, so this did not quite work. Thanks for the idea though!

You should have one main parent and make it have two children. One of them is the player one is the duplicated player. That way you can search for them separately and you can use the main parent to find them all.
This is what I did and it works great, thanks! :)
 
Top