DirtyLibrary
Member
I'm relatively new to GMS2 and looking for advice on saving DS_LISTS that have ds_maps inside of them to an ini file.
Adding the map to the list..
saving the file..
load file..
Now every attempt I've made at loading the variables, doesn't seem to work. How would I go about reading the ds_list/ds_map from the ini file? I know how to load basic variables with ini_read_string() etc. But I can't seem to read the ds_list! Can't get my head around it, can someone give me advice? Am I going about this the wrong way? Thank you!
Adding the map to the list..
Code:
global.troops = ds_list_create();
entry = ds_map_create();
ds_map_add(entry, "type", "Knight");
ds_map_add(entry, "hp", 100);
ds_list_add(global.troops, entry);
Code:
filename = "settingfile.ini";
ini_open(filename);
temp_list = ds_list_create();
length = ds_list_size(global.troops);
for(i = 0; i < length; i++) {
temp_var = ds_list_find_value(global.troops, i);
ds_list_add(temp_list, temp_var);
}
temp_list_str = ds_list_write(temp_list);
ini_write_string("Save", "troops", temp_list_str);
ds_list_destroy(temp_list);
ini_close();
Code:
global.troops = ds_list_create();
filename = "settingfile.ini";
if(file_exists(filename)) {
ini_open(filename);
temp_list = ds_list_create();
temp_list_str = ini_read_string("Save", "troops", "");
ds_list_read(temp_list, temp_list_str);
length = ds_list_size(temp_list);
for(i = 0; i < length; i++) {
val = ds_list_find_value(temp_list, i);
ds_list_add(global.troops, val);
}
ds_list_destroy(temp_list);
}
ini_close();
Last edited: