GMS 2 Loading Grid From Json Not Working Properly?

Divinik

Member
So in the game I'm currently working on, every companion and their info is stored in a ds_grid (Companions_Grid), and within each companion's column is another inventory grid stored for the companion.

The code for storing the inventory grids into the json seems to be working perfectly, I check the json files each time I run the game and all grids are there with their unique identifiers.

Here is the code for writing the inventory grid data into the ds_map for the json file:

(The ds_list named com_invData is used to find all companion inventories and read them into a ds_map. Companions_Grid[# 7, i] is the grid_position of the companion inventory.)

Code:
///In the save_instances() script

ds_list_clear(com_invData);
    
for (var i = 0; i < ds_grid_height(Companions_Grid); i++)
   {
    ds_list_add(com_invData, ds_grid_write(Companions_Grid[# 7, i]));
    var my_key = "com_inv"+string_hash_to_newline(i)+string_hash_to_newline(Companions_Grid[# 0, i]);
    ds_map_add(wrapper_map, my_key, ds_list_find_value(com_invData, i));
   }

When the load_instances() script is called, this section handles loading the companion inventories:

Code:
for (var i = 0; i < ds_grid_height(Companions_Grid); i++)
  {
   var my_key = "com_inv"+string_hash_to_newline(i)+string_hash_to_newline(Companions_Grid[# 0, i]);
 
   ds_string = wrapped_map[?my_key];
 
   if ds_string != undefined
     {
      var inv_toChange = Companions_Grid[# 7, i];
  
      ds_grid_clear(inv_toChange, undefined);
      ds_grid_resize(inv_toChange, 0, 0);
      ds_grid_read(inv_toChange, ds_string);
     }
  }
So if I execute the loading script while in the game or when I first start the game, it works without a hitch. But if I restart the game, the first companion on the grid's inventory will look like this:

upload_2020-1-14_13-41-12.png

Anyone have any idea why this is happening? Any help would be appreciated!
 
Last edited:

Divinik

Member
Are the numbers in red what the value should be? Or is that just the grid cell?
The red numbers just indicate the column. so 0 would be the very first column of the grid and so on. What is supposed to be displayed is a weapon icon, name and amount.
 

SeraphSword

Member
Your code shows a "wrapper_map" in the save script and a "wrapped_map" in the load script, are those different things?
 
Top