Creating a DS_list within a list and loading from that list

J

Jahasaja

Guest
Hi all,

I have figured out how to do saving and loading for a position within a ds_list with the help of Shaun Spaldings excellent tutorial

Saving to position 0
Code:
var _root_list = ds_list_create();
var _map_player = ds_map_create();
ds_list_add(_root_list, _map_player);
ds_list_mark_as_map(_root_list, 0);


//Wrap the root LIST up in a MAP!
var _wrapper = ds_map_create();
ds_map_add_list(_wrapper, "ROOT", _root_list);

//Save all of this to a string
var _string = json_encode(_wrapper);
SaveStringtoFile("savedgame.sav", _string);

//Nuke the data
ds_map_destroy(_wrapper);

Loading from position 0

Code:
var _wrapper = LoadJSONFromFile("savedgame.sav");
var _list = _wrapper[? "ROOT"];
var _map_player = ds_list_find_value(_list,0)
However, if possible I want to be able to both load from a position within the DS_list and also create a DS_list "sub_root_list" within this "root_list" and load from that one using:

Code:
for (var i = 0; i < ds_list_size(_list); i++)
I just do not seem to be able to figure out how to create a ds_list within the ds_list and then loading from it.

Thankful for any help..
 

TheouAegis

Member
_list = mainList[| 0];
for(var s=ds_list_size(_list), i=0; i<s; i++) {


You store the pointer to the list in the main list. So to read that inserted list, you first retrieve its pointer and then work with that pointer.
 
J

Jahasaja

Guest
_list = mainList[| 0];
for(var s=ds_list_size(_list), i=0; i<s; i++) {


You store the pointer to the list in the main list. So to read that inserted list, you first retrieve its pointer and then work with that pointer.
Thanks for the answer! I still cannot get the saving part to work. This is what i tried (obj_solid is a parent object for multiple instances)

with (obj_solid)
{
var _enemy_list = ds_list_create();
ds_list_add(_root_list,_enemy_list);
ds_list_mark_as_list(_root_list,2);

var _map_enemies = ds_map_create();
ds_list_add(_enemy_list,_map_enemies);
ds_list_mark_as_map(_enemy_list,ds_list_size(_enemy_list)-1);

var _obj_enemy = object_get_name(object_index);
ds_map_add(_map_enemies, "obj", _obj_enemy);
ds_map_add(_map_enemies, "y" , y);
ds_map_add(_map_enemies, "x" , x);
ds_map_add(_map_enemies, "image_xscale" , image_xscale);
}
 
Top