Morhighan wrote: ↑Sat Apr 01, 2017 4:50 am
This code is compatible with SteamAPI, so you can use it in conjunction with achievements and such. (ie. having an achievement unlock when players change the language.)
I'm actually stuck on how to implement an achievement for switching languages.
I have my game setup where you can toggle the languages from within preferences. So far so good.
screens.rpy
Code: Select all
frame:
label _("Languages")
hbox:
textbutton "日本語" action Language(None)
textbutton "English" action Language("english")
textbutton "简体中文" action Language("simpch")
textbutton "繁体中文" action Language("chinese")
Originally, some decision was made to make separate builds for each language and the following code in script.rpy was used:
Code: Select all
if persistent.first_boot:
persistent.first_boot = False
renpy.run(SetPreferencesDefault)
_preferences.language = "english"
persistent.last_lang = _preferences.language
grant_achievement("game_start")
if persistent.last_lang != _preferences.language:
grant_achievement("change_language")
persistent.last_lang = _preferences.language
Fairly cut and dry. If it's the first time booting up then it uses defaults for preferences and sets language to English (English isn't the primary language but I'd like it to be default which is why it's defined in the code) and the persistent.last_lang is initially set to English. Thus when starting up in another language, the last bit of the code would see that _preferences.language is set to a different language and thus achievement get.
Now that a language toggle is being used, this code does work but it only works after changing the language in game then restarting so I'm wondering what would be a better solution that doesn't require the user to restart the game. I thought maybe I could add an if statement in screens.rpy perhaps?