Anders__oo__
Member
Hi My problem is I don't really know how to save and load my map/grid back from a file
I have 2 scripts one for loading and one for saving the items in the rooms.
save item script
And a load item script
I place the loaditemback script in the room create event.
and the saveitem script in the room end event of the parent item
Now I would like to save the game and reload the game and replace the old map/grid with the saved ones..
but here I dont know how to do this..
I have tried just to save the ds_map_write and ds_map_read from ini file but it doesn't work..
Please Help!
I have 2 scripts one for loading and one for saving the items in the rooms.
save item script
Code:
///@param TheItem
var TheItem
TheItem = argument0;
if instance_exists(TheItem){
var TheGrid = ds_grid_create(ENTITY_PROPERTIES.COLUMN_COUNT,0)
with(TheItem) {
var _row = Ds_Grid_Add_row(TheGrid);
TheGrid [# ENTITY_PROPERTIES.X, _row] = x;
TheGrid [# ENTITY_PROPERTIES.Y, _row] = y;
TheGrid [# ENTITY_PROPERTIES.IMAGE_SPEED, _row] = image_speed;
TheGrid [# ENTITY_PROPERTIES.DIRECTION, _row] = direction;
TheGrid [# ENTITY_PROPERTIES.IMAGE_INDEX, _row] = image_index;
TheGrid [# ENTITY_PROPERTIES.KEY, _row] = key;
TheGrid [# ENTITY_PROPERTIES.ENTITYHP, _row] = entityHP;
TheGrid [# ENTITY_PROPERTIES.ENTITYMAXHP, _row] = entityMaxHp;
TheGrid [# ENTITY_PROPERTIES.ALPHA, _row] = alpha;
TheGrid [# ENTITY_PROPERTIES.TYPE, _row] = type;
if !is_undefined(sound){
TheGrid [# ENTITY_PROPERTIES.SOUND, _row] = sound;
}
}
var _data = room_get_name(room) + string(TheItem);
ds_map_replace(entityData, _data, ds_grid_write(TheGrid));
ds_grid_destroy(TheGrid);
}
Code:
var TheItem,TheGrid
///@param TheItem
TheItem = argument0;
var _data = room_get_name(room) +string(TheItem);
var _str = entityData[? _data]; //check to find data
if (_str == undefined) {
exit;
}
else{
var TheGrid = ds_grid_create(0,0);
ds_grid_read(TheGrid,_str);
for (var _row=0; _row < ds_grid_height(TheGrid); _row++)
{
with(instance_create_layer(0,0,"Instances",TheItem))
{
x = TheGrid[# ENTITY_PROPERTIES.X, _row];
y = TheGrid[# ENTITY_PROPERTIES.Y, _row];
image_speed = TheGrid[# ENTITY_PROPERTIES.IMAGE_SPEED, _row];
direction = TheGrid[# ENTITY_PROPERTIES.DIRECTION, _row];
image_index = TheGrid[# ENTITY_PROPERTIES.IMAGE_INDEX, _row];
key = TheGrid[# ENTITY_PROPERTIES.KEY, _row];
sound = TheGrid[# ENTITY_PROPERTIES.SOUND, _row];
alpha = TheGrid[# ENTITY_PROPERTIES.ALPHA, _row];
entityHP = TheGrid[# ENTITY_PROPERTIES.ENTITYHP, _row];
entityMaxHp = TheGrid[# ENTITY_PROPERTIES.ENTITYMAXHP, _row];
type = TheGrid[# ENTITY_PROPERTIES.TYPE, _row];
}
}
}
ds_grid_destroy(TheGrid);
I place the loaditemback script in the room create event.
and the saveitem script in the room end event of the parent item
Now I would like to save the game and reload the game and replace the old map/grid with the saved ones..
but here I dont know how to do this..
I have tried just to save the ds_map_write and ds_map_read from ini file but it doesn't work..
Please Help!
Last edited: