Thought: You cannot distinguish a number being used as a number from a number being an id for a data structure. Hence you cannot codify whether to call some kind of data serialization function or not just based on the value, you'll need to keep track of that information elsewhere (in some other way, data structure or whatever, or explicitly handle those variables on a case-by-case basis).Hello! Can I get ALL variables from my instance as ds_map? I want to save my instance (as json), but don't want to point which variables I want to save, just want to save them all. Any thoughts? Thanks!
Ouch... English is not my first language and this sentence is really hard for me. I'm not sure that I understand you correctly.Thought: You cannot distinguish a number being used as a number from a number being an id for a data structure.
Not ok if you understand that IDs returns by ds_list_create(), etc., are numbers and you have other variables that contains non-data structure number values. You are only ok if all your variables only contain numbers used for position, speed, gold coin count, etc. Again, if a variable contains a data structure id, you will have no means to determine that you need to handle it specially (json_encode(), ds_list_write(), or whatever, in contrast to string()). Knowing what names of instance variables you have does not tell you at all what the contain as far as code is concerned, unless you handle it explicitly.Ouch... English is not my first language and this sentence is really hard for me. I'm not sure that I understand you correctly.
With "variable_instance_get_names()" I will get an array with all variable names. With "variable_instance_get()" I will get that variables values.
In theory everything is OK
a = 100;
b = ds_list_create();
ds_list_add(b, 1, 2, 3);
var names = variable_instance_get_names(id);
for (var i = 0; i < array_length_1d(names); i++) {
var v = variable_instance_get(id, names);
if (names[i] == "b")
show_debug_message("saving list " + names[i] + " = " + ds_list_write(v));
else
show_debug_message("saving number "+ names[i] + " = " + string(v));
}
a = 0;
b = ds_list_create();
c = ds_map_create();
show_debug_message("a is real " + string(is_real(a)));
show_debug_message("a is list " + string(ds_exists(a, ds_type_list)));
show_debug_message("a is map " + string(ds_exists(a, ds_type_map)));
show_debug_message("b is real " + string(is_real(b)));
show_debug_message("b is list " + string(ds_exists(b, ds_type_list)));
show_debug_message("b is map " + string(ds_exists(b, ds_type_map)));
show_debug_message("c is real " + string(is_real(c)));
show_debug_message("c is list " + string(ds_exists(c, ds_type_list)));
show_debug_message("c is map " + string(ds_exists(c, ds_type_map)));
a is real 1
a is list 1
a is map 1
b is real 1
b is list 1
b is map 1
c is real 1
c is list 1
c is map 1