GML How do I save a ds_list to a ds_grid?

Dr_Nomz

Member
I thought I knew how to do this, but lot's of testing shows I have no idea how to do this.

Code:
for (var o=0; o<4; o+=1){
  var _row = scr_DSGAR(save_blue_dialogue);
  save_blue_dialogue[# save_blue_dialogue_enum.option, _row]=option[|o];
}
Basically it should just go through each and every value contained in each part of the "option" list, and save it.

But when I tried to load it, it was loaded in as a grid and had none of the correct values.

Code:
  var db0_key = room_get_name(room)+"save_blue_dialogue_string";
  var save_blue_dialogue = ds_grid_create(0,0);
  var db0_str = scr_SDGV(db0_key);
 
  ds_grid_read(save_blue_dialogue,db0_str);
  var o=0;
  for (var db0_row=0; db0_row<ds_grid_height(save_blue_dialogue); db0_row++){
    option[|o]=save_blue_dialogue[# save_blue_dialogue_enum.option, db0_row];
    o++
  }
This is how I'm loading it in. If you're confused watch this tutorial:
around 4:00 is about where he explains the important bits.
 

samspade

Member
Your code is incomplete and doesn't give enough of a clue to know what is wrong, and I don't want to watch a video to understand the problem especially since in the video which I skimmed through it seems to work just fine for him. So you either didn't follow the tutorial accidentally, in which case the solution is to re-watch the tutorial, or you are intentionally changing things and watching the video is therefore of limited use since no one knows what you're doing differently.
 
@Dr_Nomz Try following the video before you start changing things. I have used that exact video in the past and it works perfectly, so you have obviously started changing things without understanding what it is you are doing and expecting it to just work.
Two things that come straight to mind:
1. You have failed to show us all of the scripts that you are using. You call scr_DSGAR and scr_SDGV but don't show us or tell us what they do so we have no way of understanding this part of your code.
2. You have defined your ds_grid with no width. If you had been following the video you would have seen at 5:21 that this was defined using an enum to set the width to be 10, and with a height of 0. In your code you set it with a width and height of 0. So no columns.
 

Dr_Nomz

Member
Well, apparantly I needed to make that title a little clearer. How do I save a DS_LIST into a DS_GRID?

If you look closely, I'm trying to take data from option[|o], which is to say the data contained in that part of the list (o is in the for loop, so it goes through options 0-4) so I can save and load the ds_list by using the ds_grid method.
 
Well, apparantly I needed to make that title a little clearer. How do I save a DS_LIST into a DS_GRID?
That is basically exactly what you have already said. It is no clearer just because you put things in CAPS.
Here is a novel thing, have you tried putting show_debug_messages throughout these bits of code so you can see what is being run, what the values are, and what you end up with? Or even use the debugger. You are going to have to give us more to go on that just :
But when I tried to load it, it was loaded in as a grid and had none of the correct values.
What is in this enum: save_blue_dialogue_enum.option
What does this script do and what does it return as a value: var _row = scr_DSGAR(save_blue_dialogue);
What does this script do and what does it return as a value: var db0_str = scr_SDGV(db0_key);
Are your for loops actually running? How have you confirmed this? How have you confirmed the values that the loops are returning? What are the values in you option[] array?
These are the things we need to to help us out with, so we can then help you.
 

Dr_Nomz

Member
Code:
if global.load_room=0{
enum save_blue_dialogue_enum
{
  lines, //The NPC's response
  dialogue, //Which dialogue tree to use.
  hide,
  option,
  column_count
}

var save_blue_dialogue = ds_grid_create(save_blue_dialogue_enum.column_count,0);
with(obj_Blue_Dialogue){
for (var h=0; h<100; h+=1){ 
  var _row = scr_DSGAR(save_blue_dialogue);
  //NOTE: For loop starts BEFORE the _row VAR!!!
    save_blue_dialogue[# save_blue_dialogue_enum.hide, _row]=hide[h];
    //Actually just keep the _row var in the for loop,
    //then everything else after the loop. (So it doesn't save more than once)
  }
  save_blue_dialogue[# save_blue_dialogue_enum.lines, _row]=lines;
  save_blue_dialogue[# save_blue_dialogue_enum.dialogue, _row]=dialogue;
}

for (var o=0; o<4; o+=1){
  var _row = scr_DSGAR(save_blue_dialogue);
  save_blue_dialogue[# save_blue_dialogue_enum.option, _row]=ds_list_write(option);
}

var _key = room_get_name(room)+"save_blue_dialogue_string";
scr_SDSV(_key,ds_grid_write(save_blue_dialogue));

ds_grid_destroy(save_blue_dialogue);
}
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]];
That should be all the relevant data.

As for the list, when I load it back in, it loads as an array with 103 entries, and all values are 0. So the loading script must be the issue.
Code:
  var db0_key = room_get_name(room)+"save_blue_dialogue_string";
  var save_blue_dialogue = ds_grid_create(0,0);
  var db0_str = scr_SDGV(db0_key);

  ds_grid_read(save_blue_dialogue,db0_str);
  var o=0;
  for (var db0_row=0; db0_row<ds_grid_height(save_blue_dialogue); db0_row++){
    option[|o]=save_blue_dialogue[# save_blue_dialogue_enum.option, db0_row];
    o++
  }
What do I do to make it load correctly?
 

Dr_Nomz

Member
Look, I don't understand how ds_lists work, and the manual isn't very helpful, so can someone please show me how to save a ds_list? I can use maps and grids to save all kinds of variables, but it just isn't working with lists.
 

Danei

Member
I'm not seeing where you're using ds_list_read() in your load script. If you wrote them with ds_list_write, that converts them into a string of data. You need to create lists and ds_list_read the previously-written strings into them in order to have a bunch of lists again.
 
Last edited:
Top