Re: A data folder, in bgt?
So from what I could understand, You want to store all those for instance 10 save slots in a pack file as you're talking about savefiles.dat not savefile.dat. Here's how to do it.
Some people do use dictionaries and serialize them to store their save data in a file, or use pure strings and then string_encrypt them to again store the save data to a file.
If you think your variables are going to be a lot, then after adding each one, add the variable to the save function so that it is written in the save file too. Doing this as you progress further through that game's development helps you save and load all those variables with little to no effert. You don't need to add them all at once to the save and load functions because that's gonna be a pain in the back so before doing much to your game, implement the save and load functions so that you can add your variables to them before they get out of hand.
Saving and loading via dictionaries should be straight forward. You serialize the dictionaries and write them in a file when you want to save, and read them from the file and deserialize when you want to load. But how about strings. If you know parsing then this one isn't going to be a hard thing to understand/do. Simply you declare a string at the top of the save function, then do like this:
void save()
{
string data;
data+="health|"+health+"\r\n";
data+="running_speed|"+running_speed+"\r\n";
//and so on for the other variables
}
Now you save the string to a file which isn't something worth providing code I guess
now for the loading. You read the previously saved file to a string,
then you split the data string with the split point of "\r\n" so you have data names and data values each one in a separate element of the array. Then you run a for loop through the array you got by splitting the data string, and split each item in that array with the split point of |. Now just below the splitting procedure, You can do if(splitdata[0] == "name_of_variable")
my_variable=splitdata[1];
Although be careful with the type conversions. This gives you an error if my_variable is an int. In that case you should do my_variable=string_to_number(splitdata[1]);
Now if you want to pack them, You should use a pack_file instance below your save function so each file that is saved is added to the packfile you prefer for instance "data/savefiles.dat", and to load you declare another packfile instance in the top of your load function and check if the file you previously saved in the packfile exists, load it from the pack, then do those operations I mentioned above. You can even have a global pack file instance that does all these stuff/checking/saving/loading for you.
You can also before packing, encrypt your data string in the save file and after loading from the pack in the load function, decrypt the data string with the encryption key you previously used.
Hope it was clear. Don't expect yourself to clearly understand this all if You have no idea how to get pack_file/string splitting/string encryption to work. Just if You think this comment was helpful to you, save it in a file and as you progress through learning bgt, check this file out. You will find out that you're beginning to understand the parts you previously wouldn't
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector