1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML how does "is_undefined" work?

Discussion in 'Programming' started by BlueCat6123, Nov 8, 2019 at 2:44 AM.

Tags:
  1. BlueCat6123

    BlueCat6123 Member

    Joined:
    Jul 26, 2017
    Posts:
    46
    trying to use is_undefined to test if I've set a variable, but i get this error message:

    Variable o_soli.active(100039, -2147483648) not set before reading it.
    at gml_Object_o_soli_Create_0 (line 15) - if (is_undefined(active)) game_end()

    I find it kinda funny because that seems to take away the purpose of the function, or am I just using it wrong?
     
  2. Mercerenies

    Mercerenies Member

    Joined:
    Jun 21, 2016
    Posts:
    127
    is_undefined doesn't check if a variable is not defined (yes, I know how silly that sentence sounds out of context). It checks whether the value of the variable is the special sentinel value "undefined". So in your create event, you should set active to undefined, which is a special value, until you know what value to fill it in with. There's no way to see if a variable has been defined on an object, as that would be reflection and GML prioritized performance over reflection some time ago and removed all of the reflection capabilities.
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,602
    is_undefined() checks whether an existing variable or expression has been given the special null value undefined, not whether the variable exists. The latter is the job of variable_instance_exists() and variable_global_exists(). Note that these two functions take the variable name in string form to avoid dereferencing it as part of the call.
     
    Bentley likes this.
  4. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,611
    The function isn't used to test if you have declared a variable, it's used to test if a variable that already exists holds the value "undefined".

    From the manual:
    edit: ninja'd
     
    Bentley likes this.
  5. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,286
    ya, i remember when they deprecated these claiming it wasn't possible because the runner is no longer an interpreter, but the reality shows later on, they admit, it interprets bytecode to this day.

    (I hope I remember wrong or don't have a correct understanding of the situation)
     
    Last edited: Nov 8, 2019 at 3:59 AM

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