Legacy GM Saving Objects and their Values into .INI files

M

MineXide

Guest
Hi, I'm wondering how I could save individual objects with exact values into a .ini file without going through and doing

obj_flags.flag1 = ini_read_real("flags","flag1","flag1");

for each individual variable. I'm trying to make flag system, but I can't seem to figure out how to save the variables. All they consist of is a variable and then a boolean.
 

Hyomoto

Member
Whether or not you pursue this very specific implementation doesn't matter, at it's most basic a save routine is looping through data and saving it to a file, and a load routine is looping through a file and reading that data back into the game. The benefit of an ini file is it's EXTREMELY friendly to mistakes and changes. Some other options are buffers, text files, or as @maratae pointed out: data structures. Regardless of what choice you make you still have to identify the values you want to save, then write them to a file. There are 'easier' ways, but that's only assuming that you write your data in such as way as to make it easy to save. Saving/loading mechanisms can be quite complicated, especially as a game grows in complexity. That's why GM has a built in 'state save' to assist with that.

So, to answer briefly: yes, that is the way that you have to do it. There are other methods that may look shorter, but they all rely on the same basic principle: saving your values one at a time to a file.
 
M

MineXide

Guest
Whether or not you pursue this very specific implementation doesn't matter, at it's most basic a save routine is looping through data and saving it to a file, and a load routine is looping through a file and reading that data back into the game. The benefit of an ini file is it's EXTREMELY friendly to mistakes and changes. Some other options are buffers, text files, or as @maratae pointed out: data structures. Regardless of what choice you make you still have to identify the values you want to save, then write them to a file. There are 'easier' ways, but that's only assuming that you write your data in such as way as to make it easy to save. Saving/loading mechanisms can be quite complicated, especially as a game grows in complexity. That's why GM has a built in 'state save' to assist with that.

So, to answer briefly: yes, that is the way that you have to do it. There are other methods that may look shorter, but they all rely on the same basic principle: saving your values one at a time to a file.
I understand how saving works, I just was curious if it was possible to save objects into an .ini file with exact values so it could be loaded again with thos exact values
 

Hyomoto

Member
I understand how saving works, I just was curious if it was possible to save objects into an .ini file with exact values so it could be loaded again with thos exact values
To put it bluntly: no. If you wanted to save an object and two variables you'd need to save three things: the object_index of the object, and the two variables. When you load the game, you would then read back that information, create a new object and change it's variables to match. There is no way to, say, dump the object in memory to a file and load that again.
 
Top