Check if instance exists, not child object?

Discussion in 'Programming' started by wkaudio, Jun 17, 2019.

  1. wkaudio

    wkaudio Member

    Joined:
    May 23, 2019
    Posts:
    28
    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!
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,538
    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: Jun 17, 2019
    wkaudio likes this.
  3. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    423
    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.
     
    wkaudio likes this.
  4. wkaudio

    wkaudio Member

    Joined:
    May 23, 2019
    Posts:
    28
    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!

    This is what I did and it works great, thanks! :)
     
    Bayesian likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice