Re: Creating a save file in BGT

Hi there. Well, honestly this is very easy. One salution that I might recommend is one that I use and is easy, also one that works with most games. It's the dictionary object. All you do, is declair the dictionary.
dictionary save;
Then add values, with what ever keys you want, I do it like this, here is a complete function to save settings:
void save_settings()
{
dictionary d;
d.set("1", location);
d.set("2", city);
// just continue adding with 3 as the key, and the variable as the value, continue encreasing the number every value/variable you want to add
string text_to_write=serialize(d);
// now, encryption! Do this unles you want other bgt geeks to be able to change your data!
text_to_write=string_encrypt(text_to_write, "no_touching_my_data");
// now let's save our data
file f;
f.open("save.dat", "wb");
f.write(text_to_write);
f.close();} // end save function
So basicly in that function we saved all the values to a dictionary. the function wants: get(string key, ? value) and the ? value, means value can accept any type of variable.
and now, let's say we need to load that data we saved
void load_data()
{
// retrieve the data
file f;
f.open("save.dat", "rb");
string text_to_read=f.read();
f.close();
// now for decryption
text_to_read=string_decrypt(text_to_read, "no_touching_my_data");
// now to get the data back into a dictionary
dictionary d=deserialize(text_to_read);
// now, load the data
if(d.exists("1"))
d.get("1", location);
if(d.exists("2"))
d.get("2", city);
// and on and on for every new value that is saved, and there you go
}
Note that checking weather a value exists before actually restoring it is necessary or else you could end up having blank strings and zeroed integers, which might be different from default values. The get function wants: get(string key, &out ? value)
&out means it writes the data to a variable rather than returning anything, so if you have location, if said value was saved in the dictionary it would just write to the location variable. I hope that little idea helps, I do this and it works well for me.

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stefan_ilioaica via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : samtupy1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : samtupy1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Genroa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : stefan_ilioaica via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : stefan_ilioaica via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : samtupy1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : stefan_ilioaica via Audiogames-reflector

Reply via email to