1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 ds_exist requires already set variable?

Discussion in 'Programming' started by Shadowblitz16, Jun 29, 2016.

  1. Shadowblitz16

    Shadowblitz16 Member

    Jun 23, 2016
    umm can someone tell me how to properly use ds_exists to check if there is a ds_struct already set?
    the problem comes when you set the variable that your checking with ds_exist to a value.
    this overwrites the var that holds the data_struct, making ds_exists pointless

    it like you would need to check if the data_struct exists before setting the var but the var is required before you can check with ds_exists.

  2. rui.rosario

    rui.rosario Guest

    An example use of the function would be

    aList = ds_list_create();
    if (ds_exists(aList, ds_type_list)) {
    However, you would not need to initialize the variable with the creation of the data structure. You could instead do something like

    aList = undefined; // Simply declare the variable
    // Somewhere specific in code the data structure could be created, or not
    /// STEP EVENT
    // Check before using
    if (ds_exists(aList, ds_type_list)) {
        ds_list_add(aList, someValue);
    The thing is: you need a variable (or at least somewhere where you can hold the index of the created data structure) if you later want to check if it exists. So you can forward declare your variable (like in the second example) and still use the ds_exists function.
  3. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Apr 22, 2016
    -1 also works for an invalid value for a list. never though of uning undefined...

    That ds_exists function is pretty crap in the long run. just make sure you manage your variable when you delete the structure, by also setting the variable to -1 or undefined

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