Page 1 of 1

Trouble with updating the value of gui.interface_text_font

Posted: Sat Mar 18, 2017 8:42 am
by Alem
Greetings! A newbish question about variables here. I want to swap interface font and language at the same time from the options menu. Looks like it has to be done via action command, so I tried to do it by tinkering with language button snippet in screens.rpy. Like this:

Code: Select all

label _("Language")
                        
textbutton "English" action [SetVariable("gui.interface_text_font", "1.ttf"), Language(None)]
textbutton "Русский" action [SetVariable("gui.interface_text_font", "Double.ttf"), Language("russian")]
It results in a crash after clicking on the options button from game menu:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00action_data.rpy", line 50, in get_selected
    return getattr(self.object, self.field) == self.value
AttributeError: 'StoreModule' object has no attribute 'gui.interface_text_font'
Being newbie in coding really sucks :< I guess it's not really a variable, but I''m aiming for this parameter from gui.rpy:

Code: Select all

## The font used for out-of-game text.
define gui.interface_text_font = "DejaVuSans.ttf"
Changing it directly gets the job done, but I want to be able to switch between two sets of languages and interface fonts on the fly. Is there a way to do this?

Re: Trouble with updating the value of gui.interface_text_fo

Posted: Sat Mar 18, 2017 8:59 am
by gas
Use style preference actions.

Re: Trouble with updating the value of gui.interface_text_fo

Posted: Sat Mar 18, 2017 9:00 am
by Ocelot
gui variables are read-only (and you should use SetField to set members of class). Even if they weren't, they are read only once at startup, so changing them ingame would achieve nothing.
You want style translations: https://www.renpy.org/doc/html/translat ... anslations
Find every style which uses gui.interface_text_font in screens.rpy. For sake of the example, I assume that it is used only in style 'foo', and that gui.interface_text_font is set to "1.ttf".
You would need to add following lines to your translation:

Code: Select all

translate russian style foo:
    font "Double.ttf"

Re: Trouble with updating the value of gui.interface_text_fo

Posted: Sat Mar 18, 2017 11:05 am
by Alem
Ocelot wrote:gui variables are read-only (and you should use SetField to set members of class). Even if they weren't, they are read only once at startup, so changing them ingame would achieve nothing.
You want style translations: https://www.renpy.org/doc/html/translat ... anslations
Find every style which uses gui.interface_text_font in screens.rpy. For sake of the example, I assume that it is used only in style 'foo', and that gui.interface_text_font is set to "1.ttf".
You would need to add following lines to your translation:

Code: Select all

translate russian style foo:
    font "Double.ttf"
Thank you, worked like a charm.

Re: Trouble with updating the value of gui.interface_text_fo

Posted: Wed Oct 26, 2022 5:43 pm
by kamti
Ocelot wrote:
Sat Mar 18, 2017 9:00 am
gui variables are read-only (and you should use SetField to set members of class). Even if they weren't, they are read only once at startup, so changing them ingame would achieve nothing.
You want style translations: https://www.renpy.org/doc/html/translat ... anslations
Find every style which uses gui.interface_text_font in screens.rpy. For sake of the example, I assume that it is used only in style 'foo', and that gui.interface_text_font is set to "1.ttf".
You would need to add following lines to your translation:

Code: Select all

translate russian style foo:
    font "Double.ttf"
Thank you very much Ocelot!
So many years passed, but your reply helped me as well today!