Check if Variable equals existing instance id without error if it doesn't

Discussion in 'Programming' started by 2d_warrior, Apr 9, 2017.

  1. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    202
    If I set a variable to an instance id, what do I do to check later if the instance id contained in the variable exists, to avoid it throwing an error when I try to do something to the instance later, if the instance id value in the variable doesn't exist because it was destroyed. Keep in mind I'm checking with a variable name, so it also needs to not throw errors if it doesn't equal any instance id. Does what I initialize the variable as make a difference?
     
  2. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,604
    Catch the instance of that object in a variable so you can access that instance's variables easily later. However, the only way to be 100% sure that instance still exist before changing one of its variables is to use "instance_exist".
    If you have multiple instances of that object and you want to spot a specific one, you need to cycle through them with a "with" loop.
     

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