Adding a the choice to change the textbox in preferences.

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.
Message
Author
crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#16 Post by crimsonnight » Mon Jun 29, 2015 3:47 pm

trooper6 wrote:The error says the problem is an "unknown keyword custom_who_background"
So that says to me, you have used the keyword custom_who_background without defining it.
So, where do you use custom_who_background?
Where do you define it? Do you define it?
I think it's defined in my characters?:

Code: Select all

define narrator = Character(None, what_outlines=my_n)
define stw = Character(None, show_two_window=True)
define k = Character("Kira", color="#ffffff", kind=stw, what_outlines=my_k, show_custom_who_background="Namebox1.png", who_outlines = [(3, "#b6a472", 0, 0)],)
define k2 = Character(None, what_outlines=my_k)
define r = DynamicCharacter("player_name", color="#ffffff", show_two_window=True, what_outlines=my_r, show_custom_who_background="Namebox2.png", who_outlines = [(3, "#79003f", 0, 0)],)
define g = Character("Grant", color="#ffffff", kind=stw, what_outlines=my_g, show_custom_who_background="Namebox2.png", who_outlines = [(3, "#50697f", 0, 0)],)
define gs = Character("Kimmy", color="#ffffff", kind=stw, what_outlines=my_gs, show_custom_who_background="Namebox2.png", who_outlines = [(3, "#c95f8c", 0, 0)],)
I didn't have any problems before implementing the new code in this thread.
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#17 Post by SinnyROM » Mon Jun 29, 2015 8:39 pm

Sorry about that. The code I posted works with a new game and it assumes you define the characters with just their name. If you look at the top of the script.rpy snippet you'll see what I mean. The styling happens directly in the say screen, which is why it's so bloated, since there's no need to define so many style properties.

I tried to find information about custom_who_background, but I only found this post, where the code also gives me the same error: http://lemmasoft.renai.us/forums/viewto ... 56#p276856 I'm not familiar with defining styles in characters though so whatever I do to try and get it working is a dead end.

If if worked for you before, I think it's because you defined custom_who_background in your say screen somewhere. Maybe you can post that say screen and we can figure out how to modify it?

I'm actually figuring out how to apply multiple styles depending on the characters for my own game, but I haven't finished yet. If I discover a way, I'll post it as soon as I'm able!

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#18 Post by crimsonnight » Tue Jun 30, 2015 6:23 am

SinnyROM wrote:Sorry about that. The code I posted works with a new game and it assumes you define the characters with just their name. If you look at the top of the script.rpy snippet you'll see what I mean. The styling happens directly in the say screen, which is why it's so bloated, since there's no need to define so many style properties.

I tried to find information about custom_who_background, but I only found this post, where the code also gives me the same error: http://lemmasoft.renai.us/forums/viewto ... 56#p276856 I'm not familiar with defining styles in characters though so whatever I do to try and get it working is a dead end.

If if worked for you before, I think it's because you defined custom_who_background in your say screen somewhere. Maybe you can post that say screen and we can figure out how to modify it?

I'm actually figuring out how to apply multiple styles depending on the characters for my own game, but I haven't finished yet. If I discover a way, I'll post it as soon as I'm able!
Thanks again Sinny. The error I outlined in my initial post is only a small one so I wouldn't want anyone to spend too much time on this, but I'm happy to continue if it'll help people out.

I searched all my files for 'custom_who_background' and it only appears in the code I posted in my last post, and here:

Code: Select all

screen say:

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window varaint.
    if not two_window:

        # The one window variant.        
        window:
            id "window"

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    background custom_who_background

                    text who:
                        id "who"
                        
            window:
                id "window"

                has vbox:
                    style "say_vbox"

                text what id "what"
I'm not sure that's much help though!
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#19 Post by SinnyROM » Tue Jun 30, 2015 8:28 am

It's no trouble at all, because I figured it out! The say screen you posted did help. It doesn't pass in any arguments, even the usual who and what.

Code: Select all

screen say:
should be

Code: Select all

screen say(who, what, side_image=None, two_window=False,  # the usual arguments
    custom_who_background="say_who_window_background"  # for the custom namebox
):

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window varaint.
    if not two_window:

        # The one window variant.        
        window:
            id "window"

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    background custom_who_background

                    text who:
                        id "who"
                        
            window:
                id "window"

                has vbox:
                    style "say_vbox"

                text what id "what"  
So although you placed background custom_who_background in your screen and defined it in your characters, it wasn't passed in because the say screen didn't expect anything.

Now to apply the style. I recently found this way using a ConditionSwitch, which works nicely:

Code: Select all

define stw = Character(None, show_two_window=True)
define k = Character("Kira", color="#ffffff", kind=stw, what_outlines=my_k, who_outlines=[(3, "#b6a472", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox1A.png",
          "True", "Namebox1.png",
        )
    )
For the style changing, add this in any screen you like:

Code: Select all

    frame:
        has vbox
        text "Textbox Style"
        textbutton "Style" action SetField(persistent, "style", "")
        textbutton "Style A" action SetField(persistent, "style", "A")
Don't forget the default style setting at the top of your script:

Code: Select all

init python:
    persistent.style = ""
I hope it works for you! And anyone else who needs something similar.

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#20 Post by crimsonnight » Wed Jul 01, 2015 6:12 am

Great, I added it to all my characters it seems to be working perfectly, thanks a lot! How do I include changing the textbox in that code though? As it doesn't need to be on a per-character basis, I can't figure out where to put it...
This is my old code:

Code: Select all

            frame:
                style_group "pref"
                has vbox

                label _("Textbox")
                textbutton _("Standard") action Jump('pick_style1')
                textbutton _("Plain") action Jump('pick_style2')

Code: Select all

label pick_style1:
    $style.window.background = Frame("Textbox1.png", 12, 12)
    $style.rebuild()
    return

label pick_style2:
    $style.window.background = Frame("Textbox2.png", 12, 12)
    $style.rebuild()
    return
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#21 Post by SinnyROM » Wed Jul 01, 2015 8:58 am

Because the textbox styling relies on a persistent data variable, you don't need to call style.rebuild. It's also screen language (contrast it with Ren'Py scripting within a label). If you want this to be in the Preferences menu, you can add it to the screen preferences in screens.rpy. Make sure you use the code that uses SetField so it changes the persistent value properly.

The documentation has a lot of information on screens I find useful when making custom menus: http://www.renpy.org/doc/html/screens.html

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#22 Post by crimsonnight » Wed Jul 01, 2015 9:06 am

SinnyROM wrote:Because the textbox styling relies on a persistent data variable, you don't need to call style.rebuild. It's also screen language (contrast it with Ren'Py scripting within a label). If you want this to be in the Preferences menu, you can add it to the screen preferences in screens.rpy. Make sure you use the code that uses SetField so it changes the persistent value properly.

The documentation has a lot of information on screens I find useful when making custom menus: http://www.renpy.org/doc/html/screens.html
Cheers - is there a way to include it in the current (namebox) code though so that it can all be triggered with one preference setting?
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#23 Post by SinnyROM » Wed Jul 01, 2015 9:37 am

crimsonnight wrote:Cheers - is there a way to include it in the current (namebox) code though so that it can all be triggered with one preference setting?
I'm not sure what you mean. Did you want the setting on the namebox itself? Or have the setting in its own menu screen? For the former, you can add it to the say screen, or the quick_menu screen if you use it. The latter would need to have a new separate screen created. Or is it something completely different?

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#24 Post by crimsonnight » Wed Jul 01, 2015 9:58 am

SinnyROM wrote:
crimsonnight wrote:Cheers - is there a way to include it in the current (namebox) code though so that it can all be triggered with one preference setting?
I'm not sure what you mean. Did you want the setting on the namebox itself? Or have the setting in its own menu screen? For the former, you can add it to the say screen, or the quick_menu screen if you use it. The latter would need to have a new separate screen created. Or is it something completely different?
Sorry, totally my bad, haven't explained myself properly. Basically, a few people requested that I add an option to select a plain text box to my game as they were finding it hard to read. I did that using the code posted a couple of messages ago, but had a problem with the name box not changing with it (which you've now kindly helped me fix).

So at the moment, I have two different vboxes in my preferences screen, one for the textbox (which again, runs the code from a couple messages ago), and another for the name box. Instead of 2 separate settings, I'd like to combine it into one, so that for example, selecting 'Plain' in the preference menu will change both the text and name boxes to type 2. So my question is, what is the code that needs to be added so that the textbox changes with the name box?

Thanks! :)
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#25 Post by SinnyROM » Wed Jul 01, 2015 10:19 am

I see, got it! Then it's a case of adding another ConditionSwitch argument in the character's definition. Ren'Py has an argument set up by default for it: window_background.

Code: Select all

define k = Character("Kira", color="#ffffff", kind=stw, what_outlines=my_k, who_outlines=[(3, "#b6a472", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox1A.png",
          "True", "Namebox1.png",
        ),
    # styling the textbox
    window_background=ConditionSwitch(
          "persistent.style == 'A'", "Textbox1A.png",
          "True", "Textbox1.png",
        )
    )
These arguments are mentioned a bit in the documentation: http://www.renpy.org/doc/html/dialogue.html#Character
They're prefixed by who_, what_, and window_. So changing the text colour is done with the arg what_color, font size for the name is done with who_size, textbox width is window_xsize, etc. You can find all the style properties here: http://www.renpy.org/doc/html/style_properties.html
Unfortunately the namebox properties need to pass in variables, so to modify them, do the same with what we did with show_custom_who_background, where show_ is the prefix, and add them to the say screen.

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#26 Post by crimsonnight » Wed Jul 01, 2015 10:37 am

Thanks Sinny.

That only seems to change it per-character though, and it also seems to loose all styling defined for it?
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#27 Post by SinnyROM » Wed Jul 01, 2015 11:14 am

If you want to have the same textbox for everyone, I think doing it all in the say screen is best. Using the ConditionSwitch here:

Code: Select all

screen say(who, what, side_image=None, two_window=False,  # the usual arguments
    custom_who_background="say_who_window_background"  # for the custom namebox
):

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window varaint.
    if not two_window:

        # The one window variant.        
        window:
            id "window"

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    background custom_who_background

                    text who:
                        id "who"
                        
            window:
                id "window"
                
                # change textbox style
                background ConditionSwitch(
                    "persistent.style == 'A'", "Textbox1A.png",
                    "True", "Textbox1.png"
                )

                has vbox:
                    style "say_vbox"

                text what id "what"

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#28 Post by crimsonnight » Wed Jul 01, 2015 11:33 am

Hm, so now it only applies to all the characters I that the 'show_custom_who_background=ConditionSwitch' code:

Code: Select all

define narrator = Character(None, what_outlines=my_n)
define stw = Character(None, show_two_window=True)
define k = Character("Kira", color="#ffffff", kind=stw, what_outlines=my_k, who_outlines=[(3, "#b6a472", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox1A.png",
          "True", "Namebox1.png",
        )
    )
define k2 = Character(None, what_outlines=my_k)
define r = DynamicCharacter("player_name", color="#ffffff", show_two_window=True, what_outlines=my_r, who_outlines = [(3, "#79003f", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox2A.png",
          "True", "Namebox2.png",
        )
    )
define g = Character("Grant", color="#ffffff", kind=stw, what_outlines=my_g, who_outlines = [(3, "#50697f", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox2A.png",
          "True", "Namebox2.png",
        )
    )
define gs = Character("Kimmy", color="#ffffff", kind=stw, what_outlines=my_gs, who_outlines = [(3, "#c95f8c", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox2A.png",
          "True", "Namebox2.png",
        )
    )
I'm happy to add it to the others (guessing I just remove the namebox parts of the code), but it's still ignoring the style settings when it switches textbox?
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#29 Post by SinnyROM » Wed Jul 01, 2015 4:10 pm

It's because only a few characters have the argument two_window=True inheriting from the character stw, and the ConditionSwitch is applied to only the two window variant of the say screen. Try copying the ConditionSwitch to the non-window variant and it should work now.

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#30 Post by crimsonnight » Wed Jul 01, 2015 4:34 pm

SinnyROM wrote:It's because only a few characters have the argument two_window=True inheriting from the character stw, and the ConditionSwitch is applied to only the two window variant of the say screen. Try copying the ConditionSwitch to the non-window variant and it should work now.
Thanks it now seems to be working as intended, but it's still not picking up the style properties (style.window.*) - how do I fix this?
alwaysthesamebluesky.com

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot, zyric