• 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!

Legacy GM How to save inventory

C

Chungsie

Guest
So I have several lists. Wondering how to save them though so that the player has the same gear from last time. Any help is greatly appreciated.
 

obscene

Member
If you mean a ds_list ... you can use ds_list_read and ds_list_write to save/load that from an ini file...

(examples from documentation)

/// Save

var str;
ini_open("save.ini");
str =ds_list_write(list);
ini_write_string("Lists", "0", str);
ds_list_clear(list);
ini_close();

/// Load

list = ds_list_create();
ini_open("save.ini");
var str = ini_read_string("Lists", "0", "");
if str != ""
{
ds_list_read(list, str);
}
ini_close();

Look them up in the help docs if you need to know more, but that's pretty much it.
 
C

Chungsie

Guest
yes I mean ds_list. I am using read and write functions for things, I remember in ruby json file formats could save an entire hash or even array without reading or writing, I did not know if it had similar abilities in GMS
 
C

Chungsie

Guest
I'm using ds_maps for the save currently. I am not sure what method to use to save the 5 slots/lists I have.
 
G

gamedev513

Guest
I'm using ds_maps for the save currently. I am not sure what method to use to save the 5 slots/lists I have.
Honestly, if you are certain that 5 slots/lists are the max for inventory storage allowance, then why not use an Array with 5 specified indexes. Its recommended that if you know your fixed value (i.e. 5 in your case) then use an array, otherwise if your not sure (i.e. you can have endless amount of inventory slots) then you would use ds_list() functions.

Ive done this in the past, where the on-screen inventory slots (i.e. similar to the slots you see in bottom center in Minecraft) as an easily accessable Array with 10 index (0-9). Then, the remaining items that I have in my Chess are saved via ds_list().
This allowed me to easily switch items between array indexes and from chess to primary on-screen slots.

I know there is no code here, but hope this helps?
 
C

Chungsie

Guest
by slots I mean lists. so armors is its own list, weapons is its own, etc. the thing is, I am not sure how to save or load the lists in a ds_map.

I thought this could work for a save
for (i = 0; i <= ds_list_size(obj_player_stats.weapons); i += 1) {
save_data[? "weapons"] = ds_list_find_value(obj_player_stats.weapons,i);
}

but I cannot think of how to load it.
 
C

Chungsie

Guest
ya. I found an older thread on the subject and was able to see how it was done for them. And I tested it and confirmed it works. thanks everyone!
 
Top