GMS 2 List Variable in Object Editor variables editor

chamaeleon

Member
Is it a ds_list or an array when accessing such a variable in a script, function or action in gml?
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:
@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...?
 

chamaeleon

Member
@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...?
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.
 
@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...
 
Top