Page 1 of 3

Adding a the choice to change the textbox in preferences.

Posted: Wed Jun 17, 2015 1:37 pm
by crimsonnight
I'd like to add the option to select a second, plain textbox to my novel in the preferences screen. Is this possible? If so, how would I accomplish it? I can't find any documentation on the subject.

Thanks,

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

Posted: Wed Jun 17, 2015 6:44 pm
by kitsalai
Haven't tested it but here's my advice.

Textboxes are defined using styles, right? I saw this link in another thread where you can change styles in the middle of the game: http://www.renpy.org/doc/html/style.html#style.rebuild With this it should be possible to change the UI in the middle of the game. Insert another textbutton in your preference screen where the action changes the variable style.window.background and also calls the style.rebuild() function.

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

Posted: Wed Jun 17, 2015 6:51 pm
by Milkymalk
Styles aren't part of savegames, so if you change a style mid-game, the preferences will be reset every time you load a game.

What you CAN do is make a separate style and apply a variable to determine which one to use.

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

Posted: Thu Jun 18, 2015 7:25 am
by crimsonnight
Milkymalk wrote:Styles aren't part of savegames, so if you change a style mid-game, the preferences will be reset every time you load a game.

What you CAN do is make a separate style and apply a variable to determine which one to use.
I don't think it's a massive deal if it's reset every time to be honest, it's a short novel, so it shouldn't be too much of a hassle. Thanks for the advice - how would I go about doing that exactly? I know the coding used for preferences is quite different.

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

Posted: Thu Jun 18, 2015 12:28 pm
by Milkymalk
Sorry, I'm not particularly good with styles... :D I just did know that changing styles mid-game is not a good idea because I caught that info somewhere.

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

Posted: Thu Jun 18, 2015 1:28 pm
by kitsalai
Milkymalk wrote:Styles aren't part of savegames, so if you change a style mid-game, the preferences will be reset every time you load a game.

What you CAN do is make a separate style and apply a variable to determine which one to use.
You make a good point. However, it isn't hard to save a variable eg "style_number" in persistence and add a conditional statement in the init block to select the saved style at run time. Not sure if there's any tutorials on this but it's definitely possible.


crimsonnight wrote:I don't think it's a massive deal if it's reset every time to be honest, it's a short novel, so it shouldn't be too much of a hassle. Thanks for the advice - how would I go about doing that exactly? I know the coding used for preferences is quite different.
I wrote some code for this cause I was curious. It works like crap because when you click on the style button, it exits the perference screen. I couldn't find how to execute python statements from screen actions so it's really dirty... Anyway, here it is:

screens.rpy:

Code: Select all

screen preferences():
...
            frame:
                style_group "pref"
                has vbox

                label _("Style")
                textbutton _("Style 1") action Jump('pick_style1')
                textbutton _("Style 2") action Jump('pick_style2')
anywhere you want (might be good to put it with your other styles):

Code: Select all

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

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

Posted: Thu Jun 18, 2015 2:23 pm
by crimsonnight
kitsalai wrote:
Milkymalk wrote:Styles aren't part of savegames, so if you change a style mid-game, the preferences will be reset every time you load a game.

What you CAN do is make a separate style and apply a variable to determine which one to use.
You make a good point. However, it isn't hard to save a variable eg "style_number" in persistence and add a conditional statement in the init block to select the saved style at run time. Not sure if there's any tutorials on this but it's definitely possible.


crimsonnight wrote:I don't think it's a massive deal if it's reset every time to be honest, it's a short novel, so it shouldn't be too much of a hassle. Thanks for the advice - how would I go about doing that exactly? I know the coding used for preferences is quite different.
I wrote some code for this cause I was curious. It works like crap because when you click on the style button, it exits the perference screen. I couldn't find how to execute python statements from screen actions so it's really dirty... Anyway, here it is:

screens.rpy:

Code: Select all

screen preferences():
...
            frame:
                style_group "pref"
                has vbox

                label _("Style")
                textbutton _("Style 1") action Jump('pick_style1')
                textbutton _("Style 2") action Jump('pick_style2')
anywhere you want (might be good to put it with your other styles):

Code: Select all

label pick_style1:
    $style.window.background = Frame("background1.png", 12, 12)
    $style.rebuild()
    return
label pick_style2:
    $style.window.background = Frame("background2.png", 12, 12)
    $style.rebuild()
    return
That's great, thanks a lot for taking the time :)

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

Posted: Thu Jun 18, 2015 2:57 pm
by crimsonnight
Actually, would it also be possible to also change the name boxes for the different characters (to plain versions) using an if statement or something?

*EDIT* Here's what I've tried:

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)],)

label pick_style1:
    $style.window.background = Frame("Textbox1.png", 12, 12)
    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)],)
    $style.rebuild()
    return

label pick_style2:
    $style.window.background = Frame("Textbox2.png", 12, 12)
    define k = Character("Kira", color="#ffffff", kind=stw, what_outlines=my_k, show_custom_who_background="Namebox1A.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="Namebox2A.png", who_outlines = [(3, "#79003f", 0, 0)],)
    define g = Character("Grant", color="#ffffff", kind=stw, what_outlines=my_g, show_custom_who_background="Namebox2A.png", who_outlines = [(3, "#50697f", 0, 0)],)
    define gs = Character("Kimmy", color="#ffffff", kind=stw, what_outlines=my_gs, show_custom_who_background="Namebox2A.png", who_outlines = [(3, "#c95f8c", 0, 0)],)
    $style.rebuild()
    return
It only seems to be only picking up the style set for the characters under 'label pick_style2:', (I'm guessing because it's later in the script,) even if I change the preference to 'pick_style2'. I guess instead of the 'define' command, I need one that'll update the defined characters?

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

Posted: Fri Jun 19, 2015 12:04 am
by kitsalai
The define command is analogous to changing a variable's value but only works at runtime. I heard it's more robust.

Anyway, use $g = ... in your labels and it should work.

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

Posted: Fri Jun 19, 2015 3:35 am
by crimsonnight
kitsalai wrote:The define command is analogous to changing a variable's value but only works at runtime. I heard it's more robust.

Anyway, use $g = ... in your labels and it should work.
So like this for example?:

Code: Select all

$g = Character("Grant", color="#ffffff", kind=stw, what_outlines=my_g, show_custom_who_background="Namebox2A.png", who_outlines = [(3, "#50697f", 0, 0)],)
Doesn't seem to be having any effect :(

*EDIT* My bad, it does work, it just doesn't switch instantly - also, if you scroll backwards at any point, it reverts to the default definitions. Any idea on a way around this? It's just a small bug though, so don't worry too much.
Cheers,

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

Posted: Sat Jun 20, 2015 9:49 pm
by SinnyROM
The style can stay changed by using a persistent variable, even with rollback, but it'll be the same throughout all saves.
I think this may be easier in screen language, but it does make the say screen script look bloated. I gave this a try and it works (using coloured Frames - same idea though).
This is only with the textbox/namebox background image - if this works out for you, you can edit it to add the outlines too.
A good way I thought of would be to create styles for each and instead of changing the background for each if result, it would change the style instead. But I can't get it working for the what textbox. It works for the who namebox though, so it's not me, I hope! I might take another stab at this and figure out a better way.

Code: Select all

### script.rpy

# Declare characters used by this game.
define e = Character('Eileen')
define k = Character('Kira')
        
# The game starts here.
label start:

    e "You've created a new Ren'Py game."
    
    e "Once you add a story, pictures, and music, you can release it to the world!"

    k "The textbox should change because I'm talking."
    
    e "The textbox changes back."

    return

Code: Select all

### screens.rpy (say)

init python:
    # Default style
    persistent.style = "1"

init python:
    # namebox1 = "Namebox1.png"
    namebox1 = Frame("#f00",0,0)
    namebox2 = Frame("#00f",0,0)
    namebox1A = Frame("#f008",0,0)
    namebox2A = Frame("#00f8",0,0)
    
    # textbox1 = "Textbox1.png"
    textbox1 = Frame("#ff0",0,0)
    textbox2 = Frame("#0ff",0,0)
    textbox1A = Frame("#ff08",0,0)
    textbox2A = Frame("#0ff8",0,0)

screen say(who, what, side_image=None, two_window=False):

        if who:
            window:
                style "say_who_window"
                if persistent.style == "1":
                    if who == "Kira":
                        background namebox1
                    else:
                        background namebox2
                else:
                    if who == "Kira":
                        background namebox1A
                    else:
                        background namebox2A
                
                text who:
                    id "who"

        window:
            id "window"
            if persistent.style == "1":
                if who == "Kira":
                    background textbox1
                else:
                    background textbox2
            else:
                if who == "Kira":
                    background textbox1A
                else:
                    background textbox2A
                    
            vbox:
                style "say_vbox"

                text what id "what"                

Code: Select all

### screens.rpy (preferences)

screen preferences():

    # ...

            # Add this wherever you want
            frame:
                has vbox
                text "Textbox Style"
                textbutton "Style 1" action SetField(persistent, "style", "1")
                textbutton "Style 2" action SetField(persistent, "style", "2")

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

Posted: Sat Jun 27, 2015 8:41 am
by crimsonnight
SinnyROM wrote:The style can stay changed by using a persistent variable, even with rollback, but it'll be the same throughout all saves.
I think this may be easier in screen language, but it does make the say screen script look bloated. I gave this a try and it works (using coloured Frames - same idea though).
This is only with the textbox/namebox background image - if this works out for you, you can edit it to add the outlines too.
A good way I thought of would be to create styles for each and instead of changing the background for each if result, it would change the style instead. But I can't get it working for the what textbox. It works for the who namebox though, so it's not me, I hope! I might take another stab at this and figure out a better way.

Code: Select all

### script.rpy

# Declare characters used by this game.
define e = Character('Eileen')
define k = Character('Kira')
        
# The game starts here.
label start:

    e "You've created a new Ren'Py game."
    
    e "Once you add a story, pictures, and music, you can release it to the world!"

    k "The textbox should change because I'm talking."
    
    e "The textbox changes back."

    return

Code: Select all

### screens.rpy (say)

init python:
    # Default style
    persistent.style = "1"

init python:
    # namebox1 = "Namebox1.png"
    namebox1 = Frame("#f00",0,0)
    namebox2 = Frame("#00f",0,0)
    namebox1A = Frame("#f008",0,0)
    namebox2A = Frame("#00f8",0,0)
    
    # textbox1 = "Textbox1.png"
    textbox1 = Frame("#ff0",0,0)
    textbox2 = Frame("#0ff",0,0)
    textbox1A = Frame("#ff08",0,0)
    textbox2A = Frame("#0ff8",0,0)

screen say(who, what, side_image=None, two_window=False):

        if who:
            window:
                style "say_who_window"
                if persistent.style == "1":
                    if who == "Kira":
                        background namebox1
                    else:
                        background namebox2
                else:
                    if who == "Kira":
                        background namebox1A
                    else:
                        background namebox2A
                
                text who:
                    id "who"

        window:
            id "window"
            if persistent.style == "1":
                if who == "Kira":
                    background textbox1
                else:
                    background textbox2
            else:
                if who == "Kira":
                    background textbox1A
                else:
                    background textbox2A
                    
            vbox:
                style "say_vbox"

                text what id "what"                

Code: Select all

### screens.rpy (preferences)

screen preferences():

    # ...

            # Add this wherever you want
            frame:
                has vbox
                text "Textbox Style"
                textbutton "Style 1" action SetField(persistent, "style", "1")
                textbutton "Style 2" action SetField(persistent, "style", "2")
Thanks a lot for this, and apologies for the delay. I've added the code, but when starting the game I'm getting the following error:

Code: Select all

While running game code:
  File "game/script.rpy", line 2193, in script
    g "Are you going on this adventure as a male or female?"
Exception: Unknown keyword arguments: custom_who_background

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

Posted: Sat Jun 27, 2015 1:43 pm
by SinnyROM
Could you post your code surrounding the error line, line 2193? Also how you changed the say screen, and if you changed how you defined your characters.

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

Posted: Mon Jun 29, 2015 5:49 am
by crimsonnight
SinnyROM wrote:Could you post your code surrounding the error line, line 2193? Also how you changed the say screen, and if you changed how you defined your characters.
I have changed anything yet, I've just added the code as-is for now to try and get it working first.

Here's the traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 2193, in script
    g "Are you going on this adventure as a male or female?"
Exception: Unknown keyword arguments: custom_who_background

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

Full traceback:
  File "game/script.rpy", line 2193, in script
    g "Are you going on this adventure as a male or female?"
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\ast.py", line 593, in execute
    renpy.exports.say(who, what, interact=self.interact)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\exports.py", line 1021, in say
    who(what, interact=interact)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\character.py", line 826, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\character.py", line 688, in do_display
    **display_args)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\character.py", line 465, in display_say
    what_text = show_function(who, what_string)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\character.py", line 672, in do_show
    **self.show_args)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\character.py", line 275, in show_display_say
    return renpy.display.screen.get_widget(screen, "what", layer)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\display\screen.py", line 988, in get_widget
    screen.update()
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\display\screen.py", line 556, in update
    self.screen.function(**self.scope)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\ast.py", line 148, in apply_arguments
    return parameters.apply(args, kwargs, ignore_errors)
  File "G:\Google Drive\Crimson Night LTD\Always The Same Blue Sky\Visual Novel Project\Ren'Py\Ren'Py\renpy\ast.py", line 136, in apply
    raise Exception("Unknown keyword arguments: %s" % ( ", ".join(values.keys())))
Exception: Unknown keyword arguments: custom_who_background

Windows-8-6.2.9200
Ren'Py 6.99.4.467
Always The Same Blue Sky... 2.16
Here's the code surround that line:

Code: Select all

    return
    
label startchoices:
    
    g "Are you going on this adventure as a male or female?"
    
    menu:
        "♂ Male":
            $ gender = 0
            $ steam.unlock_achievement('Mars')
            $ achievement.grant("Mars")
            
        "♀ Female":
            $ gender = 1
            $ steam.unlock_achievement('Venus')
            $ achievement.grant("Venus")
Thanks :)

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

Posted: Mon Jun 29, 2015 12:47 pm
by trooper6
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?