Adding Text Box opacity Properties to "Reset to Defaults"

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
yoyuchi
Regular
Posts: 61
Joined: Sat Jul 09, 2022 1:39 pm
Contact:

Adding Text Box opacity Properties to "Reset to Defaults"

#1 Post by yoyuchi »

Adding Text Box opacity Properties to "Reset to Defaults"
With the help of the forum, I added the Text Box opacity and Settings Reset button to preferences.
Reset button allows initialization such as sound volume and afm_time, etc, but text box opacity cannot be initialize.

Here's my reset script.

Code: Select all

define persistent.dialogueBoxOpacity = 1.0

Code: Select all

label ResetToDefaults:   
    python:
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
        _persistent.dialogueBoxOpacity = 1.0

    jump preferences_screen
There were also _preferences.text_cps, _preferences.transitions, etc. on the Renpy page,
but no variables related to text box opacity were found.
I didn't know well, so at the end, "_persistent.dialogueBoxOpacity = 1.0" I've tried it, but there's an error.
I think it would be possible to write a variable related to opacity at the end of the command line above, but what should I write?
I ask for your advice. Thank you.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1035
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#2 Post by m_from_space »

What do you mean by "text box"? A "text" object as part of a screen? The dialogue window?

Your last line reads "_persistent.dialogueBoxOpacity" instead of "_preferences.", although both make no sense. ;-)

When in your game does the opacity of that "text box" change?

yoyuchi
Regular
Posts: 61
Joined: Sat Jul 09, 2022 1:39 pm
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#3 Post by yoyuchi »

m_from_space wrote: Wed Jul 13, 2022 1:25 pm What do you mean by "text box"? A "text" object as part of a screen? The dialogue window?

Your last line reads "_persistent.dialogueBoxOpacity" instead of "_preferences.", although both make no sense. ;-)

When in your game does the opacity of that "text box" change?
I made a bar to control the opacity of the dialogue window in the preference. Opacity of the dialog window changes as I adjust the bar. I click "Reset Settings button", all other items can be reset, but I don't know what to add to reset opacity.

I know that my _persistent.dialogueBoxOpacity = 1.0 is meaningless. I've been testing a lot of things. Obviously, if there is an appropriate instruction in that position, the opacity can be reset.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1035
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#4 Post by m_from_space »

So as I already asked: How exactly do you change the opacity in your game? Show me the code!

yoyuchi
Regular
Posts: 61
Joined: Sat Jul 09, 2022 1:39 pm
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#5 Post by yoyuchi »

m_from_space wrote: Thu Jul 14, 2022 2:32 am So as I already asked: How exactly do you change the opacity in your game? Show me the code!
I'm so sorry for the late response.
Here's my script.

Code: Select all

label ResetToDefaults:  
    python:
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
     #   _persistent.dialogueBoxOpacity = 1.0
    
    jump preferences_screen

screen preferences():
        #on "hide" action set_window_opacity
        #on "replaced" action set_window_opacity
       
        tag menu
        add "grp/parts/prefBG.png"
        use navigation2
     
        grid 2 1:
            style_group "prefs"
            xfill True
       
            vbox:
                vbox:
                    style_prefix "prefs"
                    bar value Preference("text speed") 
                    pos(75, 117) 
                    
                vbox:
                    style_prefix "prefs"
                    bar value Preference("auto-forward time") 
                    pos(75, 180)

                vbox:
                    hbox:
                        imagebutton:
                            idle "grp/parts/config/Pkid_YES_idle.png"
                            hover "grp/parts/config/Pkid_YES_hover.png"
                            selected_idle "grp/parts/config/Pkid_YES_selected.png"
                            selected_hover "grp/parts/config/Pkid_YES_hover2.png"
                            pos(80, 247) 
                            action Preference("skip", "all")
                            
                        imagebutton:
                            idle "grp/parts/config/Pkid_NO_idle.png"
                            hover "grp/parts/config/Pkid_NO_hover.png"
                            selected_idle "grp/parts/config/Pkid_NO_selected.png"
                            selected_hover "grp/parts/config/Pkid_NO_hover2.png"
                            pos(40, 247) 
                            action Preference("skip", "seen")
                          
                        spacing 40
                        align (.1, .5)

                vbox:
                    hbox:
                        imagebutton:
                            idle "grp/parts/config/Ptran_YES_idle.png"
                            hover "grp/parts/config/Ptran_YES_hover.png"
                            selected_idle "grp/parts/config/Ptran_YES_selected.png"
                            selected_hover "grp/parts/config/Ptran_YES_hover2.png"
                            pos(80, 300)     
                            action Preference("transitions", "all")

                        imagebutton:
                            idle "grp/parts/config/Ptran_NO_idle.png"
                            hover "grp/parts/config/Ptran_NO_hover.png"
                            selected_idle "grp/parts/config/Ptran_NO_selected.png"
                            selected_hover "grp/parts/config/Ptran_NO_hover2.png"
                            pos(40, 300) 
                            action Preference("transitions", "none")
                        spacing 40
                        align (.1, .5)
  
                vbox:
                    hbox:
                        imagebutton:
                            idle "grp/parts/config/Pskip_YES_idle.png"
                            hover "grp/parts/config/Pskip_YES_hover.png"
                            selected_idle "grp/parts/config/Pskip_YES_selected.png"
                            selected_hover "grp/parts/config/Pskip_YES_hover2.png"
                            pos(80, 353)     
                            action Preference("after choices", "skip")

                        imagebutton:
                            idle "grp/parts/config/Pskip_NO_idle.png"
                            hover "grp/parts/config/Pskip_NO_hover.png"
                            selected_idle "grp/parts/config/Pskip_NO_selected.png"
                            selected_hover "grp/parts/config/Pskip_NO_hover2.png"
                            pos(40, 353) 
                            action Preference("after choices", "stop")
                        spacing 40
                        align (.1, .5)
                spacing 20

                pos (80, 70)
    
            vbox:
                style_group "prefs"
                vbox:
                    bar value Preference("music volume") #at bar_transform  
                vbox:
                    bar value Preference("voice volume") 
                    pos(10, 180)

                vbox:
                    bar value Preference("sound volume") 
                    pos(10, 248)
                               
                vbox:
                    bar value FieldValue(persistent, "dialogueBoxOpacity", range=1.0, style="slider")
                    pos(10, 310)
                                 
                spacing 20
                pos (60, 70)       
 
        imagebutton:
            idle "grp/parts/back_idle.png"
            hover "grp/parts/back_hover.png"
            pos (1387, 803)
            action Return()


        imagebutton:                                     
                idle "grp/parts/reset_idle.png"
                hover "grp/parts/reset_hover.png"
                pos (1337, 25)
                action Confirm("設定を初期化しますか?", yes=Jump("ResetToDefaults"))  
       

        key "mouseup_3" action Return()     

At the bottom of the script,

Code: Select all

vbox:
     bar value FieldValue(persistent, "dialogueBoxOpacity", range=1.0, style="slider")
     pos(10, 310)
is the opacity control part.

And reset to default is

Code: Select all

imagebutton:                                     
    idle "grp/parts/reset_idle.png"
    hover "grp/parts/reset_hover.png"
    pos (1337, 25)
    action Confirm("設定を初期化しますか?", yes=Jump("ResetToDefaults"))  

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1035
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#6 Post by m_from_space »

Oh now I know what your problem is, I didn't realize what you were trying to do.

You accidentally added an underscore in front of "persistent". The persistent object does not have an underscore.

Just write:

Code: Select all

label ResetToDefaults:  
    python:
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
        persistent.dialogueBoxOpacity = 1.0

yoyuchi
Regular
Posts: 61
Joined: Sat Jul 09, 2022 1:39 pm
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#7 Post by yoyuchi »

m_from_space wrote: Sun Jul 17, 2022 3:11 pm Oh now I know what your problem is, I didn't realize what you were trying to do.

You accidentally added an underscore in front of "persistent". The persistent object does not have an underscore.

Just write:

Code: Select all

label ResetToDefaults:  
    python:
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
        persistent.dialogueBoxOpacity = 1.0
Thank you for your reply.
Following your advice, I used "persistent.dialogueBoxOpacity = 1.0",
and the following error occurred.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00barvalues.rpy", line 285, in get_adjustment
    value -= self.offset
TypeError: unsupported operand type(s) for -=: 'NoneType' and 'float'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_preferences.rpym", line 29, in script
    $ ui.interact()
  File "renpy/ast.py", line 928, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2245, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/_layout/screen_preferences.rpym", line 29, in <module>
    $ ui.interact()
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3325, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3737, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 441, in visit_all
    self.child.visit_all(callback, seen=None)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 570, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3737, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/behavior.py", line 1893, in per_interact
    adjustment = self.value.get_adjustment()
  File "renpy/common/00barvalues.rpy", line 285, in get_adjustment
    value -= self.offset
TypeError: unsupported operand type(s) for -=: 'NoneType' and 'float'

Windows-7-6.1.7601-SP1
Ren'Py 7.4.11.2266
sam 1.0
Mon Jul 18 23:37:26 2022
What should I do next? I am sorry for continuing question. :|

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1035
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#8 Post by m_from_space »

I don't think that error refers to the code I gave you. When exactly does it happen? Looks like it is about your bar. Did it work before?

Make sure the variable "persistent.dialogueBoxOpacity" is created in the init phase, when it is not known already:

Code: Select all

init python:
    if persistent.dialogueBoxOpacity is None:
        persistent.dialogueBoxOpacity = 1.0

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1035
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#9 Post by m_from_space »

By the way, I don't recommend using a label for just changing variables. Labels are used for the flow of the game / story, not for managing stuff.

Write a python function instead:

Code: Select all

init python:
    def resetToDefaults():
        global _preferences, persistent
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
        persistent.dialogueBoxOpacity = 1.0
        return
Call the function inside the screen using:

Code: Select all

imagebutton:                                     
    idle "grp/parts/reset_idle.png"
    hover "grp/parts/reset_hover.png"
    pos (1337, 25)
    action Confirm("設定を初期化しますか?", yes=Function(resetToDefaults))

yoyuchi
Regular
Posts: 61
Joined: Sat Jul 09, 2022 1:39 pm
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#10 Post by yoyuchi »

m_from_space wrote: Mon Jul 18, 2022 3:06 pm By the way, I don't recommend using a label for just changing variables. Labels are used for the flow of the game / story, not for managing stuff.

Write a python function instead:

Code: Select all

init python:
    def resetToDefaults():
        global _preferences, persistent
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
        persistent.dialogueBoxOpacity = 1.0
        return
Call the function inside the screen using:

Code: Select all

imagebutton:                                     
    idle "grp/parts/reset_idle.png"
    hover "grp/parts/reset_hover.png"
    pos (1337, 25)
    action Confirm("設定を初期化しますか?", yes=Function(resetToDefaults))
OK. I will try according to your advice, and report results. Thank you.
It may seem trivial, but it's very difficult if I don't know. The "program" is.

yoyuchi
Regular
Posts: 61
Joined: Sat Jul 09, 2022 1:39 pm
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#11 Post by yoyuchi »

yoyuchi wrote: Mon Jul 18, 2022 4:12 pm
m_from_space wrote: Mon Jul 18, 2022 3:06 pm By the way, I don't recommend using a label for just changing variables. Labels are used for the flow of the game / story, not for managing stuff.

Write a python function instead:

Code: Select all

init python:
    def resetToDefaults():
        global _preferences, persistent
        _preferences.transitions = 2    # All transitions on
        _preferences.text_cps = config.default_text_cps
        _preferences.afm_time = config.default_afm_time
        _preferences.skip_unseen = False
        _preferences.skip_after_choices = False
        _preferences.set_volume('music', 0.5)
        _preferences.set_volume('voice', 0.8)
        _preferences.set_volume('sfx', 0.6)
        persistent.dialogueBoxOpacity = 1.0
        return
Call the function inside the screen using:

Code: Select all

imagebutton:                                     
    idle "grp/parts/reset_idle.png"
    hover "grp/parts/reset_hover.png"
    pos (1337, 25)
    action Confirm("設定を初期化しますか?", yes=Function(resetToDefaults))
OK. I will try according to your advice, and report results. Thank you.
It may seem trivial, but it's very difficult if I don't know. The "program" is.
As you advised, the opacity can be reset by subtracting the "_". I am so grateful for your help.
Can I ask you questions about other things if you don't mind? I think it will be a great help, so I would like sincerely ask for it.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1035
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding Text Box opacity Properties to "Reset to Defaults"

#12 Post by m_from_space »

yoyuchi wrote: Thu Jul 21, 2022 12:02 pm Can I ask you questions about other things if you don't mind? I think it will be a great help, so I would like sincerely ask for it.
You don't have to ask if you you can ask questions here. Others might answer, too.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot]