• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Tread solved Remember Items

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
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);
}
And a load item script

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:

XD005

Member
Have you tried using ds_map_secure_save()/load?
I don't use the regular ones, typically. But the secure ones seem to work with no fuss or is this level data?
 
Have you tried using ds_map_secure_save()/load?
I don't use the regular ones, typically. But the secure ones seem to work with no fuss or is this level data?

I think there is an issue WHEN i save or WHEN i load back the items Order wise in the game.. If i restart the game it works with secure but not all the items are back all the time??

I Dont wanna use secure save and load system due to cloud save issues..
 
Last edited:
These are some of the scenarios I am testing: "using secure save/load for now until fixed other save method"

//leave room "works"
1. find item
2. leave room 1
3. savegame
4. return to room 1
5. load game to room 2
6. return to room 1
7. Item exists

//leave room "works"
1. find item
2. leave room 1
3. savegame
4. load game
5 return to room 1
6. Item Exists

//same room "dont work"
1. savegame
2. finditem
3. load game
4. item exists (It should have been destroyed)

//leave room "works
1. savegame
2. finditem
3. leave room 1
3. load game
4. item does not exists

I place the loaditem script in the room create event.

and the saveitem script in the room end event of the parent item

save and load is just secure save and load for now.

Can't figure out why it doesn't work....
 
Top