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

GMS 2 List Variable in Object Editor variables editor

Discussion in 'Programming' started by Niall Edwards, Nov 29, 2019.

  1. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    26
    Is it a ds_list or an array when accessing such a variable in a script, function or action in gml?
     
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,469
    I literally have no idea what you just said.
     
    Niall Edwards likes this.
  3. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    992
    It is an array if you select Multi-select, otherwise it contains whatever data type (string, number, etc.) the selected item is out of all the possible values you provide. When you say you want the variable to be a list, in the interface, you're not saying you want the variable to contain a list at runtime, you're telling the GUI to give you the ability to have a list to pick values from at design time and whatever type that value is, is what you'll have at runtime. I suspect that GMS is more or less doing a textual replacement when compiling so you could write anything you want there that is a valid expression that could be on the right-hand side of an assignment roughly as if you had written a variable initialization yourself.
     
    Last edited: Nov 30, 2019
    Niall Edwards likes this.
  4. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    26
    @obscene , hah! It was posted later in the evening...!

    @chamaeleon , so, I think you're saying that the 'list' I create in that part of the Object Editor can be accessed, interrogated and added to in gml as an array? Presumably, in gml, if I ask if that variable is an array it will return as true?

    The reason I'm asking is I'm writing a save system which interrogates all variables in an instance, all defined instance types, and saves their relevant pre-built and defined variables, their type and value... So, will such code think this particular 'list' variable is an array? I think you are saying, yes it will...?
     
  5. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    992
    Good luck with that kind of saving system, as you cannot distinguish between ds_lists, ds_maps, ds_grids assigned to a variable, etc., due to the creation functions not keeping the values unique across all data structures. Because of this you can have a ds_list with id 0 and a ds_map with id 0, and ds_exists(0, ds_list) as well as ds_exists(0, ds_map) will return true, and you cannot tell without metadata what a given variable refers to (is the given variable a ds_list or a ds_map if both exists, but 0 is assigned to two different variables), or if it's just a number like a position or index and not an data structure id.

    The only thing that gives a number meaning as a data structure id is that you call a function that operates upon the given data structure type. It just comes down to your code embodying that knowledge implicitly because you wrote code to call the appropriate function because you knew what you stored (or, again, you rely on some piece of metadata that tells you what a given variable contains..)

    Anyway, if you select the Multi-select option after adding two default values to a list (Item 0 and Item 1), you get output like
    Code:
    show_debug_message("is_array(testvar) = " + string(is_array(testvar)));
    show_debug_message("testvar = " + string(testvar));
    show_debug_message("testvar[0] = " + string(testvar[0]));
    
    Code:
    is_array(testvar) = 1
    testvar = { { Item 0,Item 1 },  }
    testvar[0] = Item 0
    
    As you can see, testvar is an array. If you do not select Multi-select, the variable will contain either Item 0 or Item 1 as strings (in this particular case, because I used the two default string values when adding items) depending on what you had selected at the time of compilation.
     
    Niall Edwards likes this.
  6. Niall Edwards

    Niall Edwards Member

    Joined:
    Nov 7, 2019
    Posts:
    26
    @chamaeleon ,

    Thanks again. No worries re the data structures. I am not using them directly in runtime instances but only to save out. In runtime, it's arrays. Hence the arrays within arrays question. And with arrays (1D) I am labelling and saving them out within ds_maps as ds_lists, if you see what I mean...
     

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