• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

SOLVED Saving a nested list mayhem!

Adry

Member
Hi everyone! I'm completely new to the list function but I figured this would be a good way to store multiple dialogue flags to save.. Can anyone offer some insight? I have the saving function of:
GML:
ds_map_add(_map, "Dialogue_flags", global.dialogue_flags);
(p.s. the flag is set to 0 within my NPC, and then 1 when the dialogue is altered, that # value is what I'm trying to save and load)

I created a persistent object controller that I want to have house that information within a global list. this is in the create event:
Code:
global.dialogue_flags = ds_list_create();

ds_list_add(global.dialogue_flags,

obj_edison_phone.dialogue_flag

);
I'm trying to load it with this code, this isn't the full code, but it works because I've saved/loaded things before but never a nested list within one global variable..

Code:
global.dialogue_flags = _map [? "Dialogue_flags"];
ds_list_find_value(global.dialogue_flags, 0)
Also I've posted on Reddit. I got replies that said I need to use ds_list_write and ds_list_read? also ds_list_mark_as_list!? I have no idea where to put these functions.. I can't get it to work. Anyone have any ideas? Help would be so greatly appreciated! Thank you :)
 
"I can't get it to work" is not a helpful phrase. Better one is "I wanted X to happen, but Y happens".
Do you face any errors? Does the data not load correctly? Did you try using the debugger?
 

Adry

Member
"I can't get it to work" is not a helpful phrase. Better one is "I wanted X to happen, but Y happens".
Do you face any errors? Does the data not load correctly? Did you try using the debugger?
Sorry about that, I don't get any errors, the flag definitely sets to 1. I just did a debug with show_debug_message(global.dialogue_flags); and it's saying the value is 0? So I must not be transferring that value correctly in some part of the code?
 
In GM, every data structure is denoted by a number, aka it’s index. The first list in your game is indexed 0, the second one is 1, then 2, 3... and so on. Same goes for maps, grids and what-not. (except arrays, because those are the only 'real' data structures in GM)
If you want to see the elements in the list, open up the debugger, right click the variable and select View As > List. You can see the elements there.
 

Adry

Member
Cool I didn't know you could do that! I found my dialogue flags with the value of 0? Like it's not storing this
GML:
ds_list_add(global.dialogue_flags, obj_edison_phone.dialogue_flag);
am I not reading it with the write function?
 
Nope, everything seems fine. As I said, the value of the list is just an index. That does not reflect what contents it has.
 

Nidoking

Member
If you want to know obj_edison_phone.dialogue_flag, you use the following bit of code:

GML:
obj_edison_phone.dialogue_flag
Be sure to copy it carefully, as it's very complicated.

If, on the other hand, you were intending to store a pointer to another variable in your list, such that when you change the obj_edison_phone.dialogue_flag elsewhere, the list magically updates its contents as well... sorry, but that's not happening in GML. You could possibly store the id of the obj_edison_phone and then use that to get its dialogue_flag variable. If everything you put in the list is an id of an instance with a dialogue_flag variable, you're golden. If not, you need a redesign or a move to a language that has variable references.
 
Top