Re: 2 important questions regarding BGT.

If you want to make translations user-editable, like Swamp, then you wouldn't be able to use serialization.
The key is to understand how to store and retrieve information in strings.

I'd probably do it like this (just an example; you will probably need to come up with something more suited to your project):

string translate(string source) {
    string result;
    language.get(source, result);
    return (result=="") ? source : result;
}

bool load_translation(string language) {
    if(!file_exists(language + ".lng")) return false;
    file fin;
    fin.open(language + ".lng", "r");
    string txt=string_replace(fin.read(0), "\r", "\n", true); // Windows line breaks are weird.
    fin.close();
    string[] lines=string_split(txt, "\n", true);
    for(uint i=0; i<lines.length(); i+=2) {
        if(i<lines.length()-1) lang.set(lines[i], lines[i+1]);
    }
    return true;
}

I would probably use serialization for other settings, though, since you wouldn't need to edit your save/load functions when you add/remove settings.
For example:

dictionary config;

void load_settings() {
    if(!file_exists("my_game.cfg")) return;
    file fin;
    fin.open("my_game.cfg", "rb");
    config=deserialize(fin.read(0)); // You could encrypt it, if you want.
    fin.close();
}

void save_settings() {
    file fout;
    fout.open("my_game.cfg", "wb");
    fout.write(serialize(config));
    fout.close();
}

void main() {
    load_settings();
    if(config.exists("language")) {
        string language;
        config.get("language", language);
        load_translation(language);
    }
    if(config.exists("no logo")==false) logo();
    // Etc...
}

void settings_menu() {
    // If you use a dynamic_menu, it might look like this:
    int result=settingsmenu.run("settingsmenu.ogg", false);
    string n=settingsmenu.get_item_name(result);
    if(n=="logo")
    {
        if(config.exists("no logo")) config.delete("no logo"); // I forget the method name for removing from dictionaries. Remove? Destroy?
        else config.set("no logo", 1);
    }
    else if(n=="language") {
        dynamic_menu languagemenu;
        string[] files=find_files("*.lng");
        for(uint i=0; i<files.length(); i++) {
            languagemenu.add_item_tts(string_left(files[i], files[i].length()-4), files[i]);
        }
        languagemenu.add_item_tts("cancel", "cancel");
        result=languagemenu.run(translate("choose language"), true);
        n=languagemenu.get_item_name(result);
        if(n!="cancel") config.set("language", n);
    }
}

hth

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

Reply via email to