Instance_exists undefined?

Discussion in 'Programming' started by Kieran Hayns, Aug 14, 2019.

  1. Kieran Hayns

    Kieran Hayns Member

    Joined:
    Oct 27, 2016
    Posts:
    12
    Im creating an RTS.

    The screen has a control panel.

    Yoi select the unit and then when you select the options on the panel it applies to that unit (move, stop, attack move etc)

    However when there isent a selected unit or the currently selected unit has been destroyed i want the buttons on the panel to be unusable until a new unit.is selected.

    I kept it simple as the control panel stores the Unit_Selected variable and when the button is pushed it says

    If instance_exists(Unit_Selected)
    {
    Do stuff
    }

    I have also done this as Unit_Selected.id


    The problem:

    When the unit exists it works however when the instance is destroyed a d i push a button it returns it as undefined rather than as false.

    I swear ive done this loads of times and it has worked. What am i doing wrong?
     
  2. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    321
    what you want to do is when you handle destroying the instance you want to check if it is currently the Unit_Selected and if so set Unit_Selected = noone prior to destroying the instance then your instance_exists should work properly.
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,865
    When done in that manner, OP could then simply check if(Unit_Selected != noone) instead of using instance_exists().
     
  4. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    321
    That too. Just a matter of which you find more readable. It would be the same net effect.
     

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