Dr_Nomz
Member
Normally when I want to save and load something, I would take, for example, an enemy's local variables and save them using a controller object in the room end event. I can do the same with global variables.
I would use an enumerator with a ds_grid to save all the data to a string to be stored in a ds_map, and loaded back in the same way.
But I can only do that for local/global variables, ds_lists don't seem to work the same way. So how do I do it?
Here's my code for reference:
I would use an enumerator with a ds_grid to save all the data to a string to be stored in a ds_map, and loaded back in the same way.
But I can only do that for local/global variables, ds_lists don't seem to work the same way. So how do I do it?
Here's my code for reference:
Code:
//obj_Control, Room End event (saving)
///Save Inventory Slots
if global.load_room=0{
enum save_inventory
{
kind,
count,
column_count
}
var inventory_save = ds_grid_create(save_inventory.column_count,0);
for (var i=0;i<maxItems;i+=1){
var _row = scr_DSGAR(inventory_save);
inventory_save[# save_inventory.kind, _row]=global.inventory[i];
inventory_save[# save_inventory.count, _row]=global.inventory_count[i];
}
var _key = "inventory_save_string";
scr_SDSV(_key,ds_grid_write(inventory_save));
ds_grid_destroy(inventory_save);
}
Code:
//Loading the game with a script from a file (ds_map_secure_load)
var _key = "inventory_save_string"; //start Inventory Load
var inventory_save = ds_grid_create(0,0);
var _str = scr_SDGV(_key);
ds_grid_read(inventory_save,_str);
var i = 0;
for (var _row=0;_row<ds_grid_height(inventory_save);_row++){
global.inventory[i]=inventory_save[# save_inventory.kind, _row];
global.inventory_count[i]=inventory_save[# save_inventory.count, _row];
i++;
}
ds_grid_destroy(inventory_save); //end Inventory Load
Code:
///scr_DSGAR(grid index)
//scr_ds_grid_add_row
//Adds a row to the grid and returns the index of the new row
var _grid = argument[0];
ds_grid_resize(_grid,ds_grid_width(_grid),ds_grid_height(_grid)+1);
return(ds_grid_height(_grid)-1);
Code:
///scr_SDSV(key,value)
//scr_save_data_set_value
with(obj_Control)
ds_map_replace(save_data,argument[0],argument[1]);
Code:
///scr_SDGV(key)
//scr_save_data_get_value
with(obj_Control)
return save_data[? argument[0]];