Custom choice button per scene

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
sg27digital
Newbie
Posts: 3
Joined: Sun Nov 06, 2022 6:22 pm
Contact:

Custom choice button per scene

#1 Post by sg27digital »

Hi

I'm trying to customize my choice_button_width specifically for one section of my game.
Why?
Well in one scene I have 10 possible replies which are quite long. For this I would like to make the choice buttons as wide as possible so that all 10 replies fit the screen nicely.
I can do this by changing gui.choice_button_width
However, this changes it for all buttons, not just in this scene.

I found this post:
viewtopic.php?f=8&t=59124&p=530133&hili ... th#p530133
Which contains something sort of similar, although it uses style's as a differentiator.

So now I'm wondering: can I apply this, but to the width of the button?

So expected result:

Code: Select all

label scenestart:
$ choice_button_wide = True
menu:
	"Option 1":
		"Answer"
	"Option 2":
		"Answer"
...
$ choice_button_wide = False
Meaning I expect only the menu in between my variables to have the gui.choice_button_width set to a larger number.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Custom choice button per scene

#2 Post by enaielei »

If you'll look into your screens.rpy there is a screen called "choice" there.
In that screen, you can alter the textbutton a bit to look like this.

Code: Select all

# important to default your variable so it stays global and the screen wont throw any error.
default choice_button_wide = False

screen choice(items):
    ...
    textbutton i.caption:
        if choice_button_wide:
            xsize 900
Then you can do the thing that your did in your code.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Custom choice button per scene

#3 Post by _ticlock_ »

sg27digital wrote: Sun Nov 06, 2022 6:54 pm
Writing

Code: Select all

$ choice_button_wide = True
...
$ choice_button_wide = False
is not very convenient. Instead, I suggest to add additional argument button_width to the choice menu:

screens.rpy

Code: Select all

screen choice(items, button_width = 500):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action xsize button_width
In this case you can use menu without arguments for normal size (button_width = 500), and specify the button_width argument if you need it:

Code: Select all

label start:
    menu:
        "Option 1":
            "Answer"
        "Option 2":
            "Answer"
    menu(button_width = 900):
        "Option 1":
            "Answer"
        "Option 2":
            "Answer"

sg27digital
Newbie
Posts: 3
Joined: Sun Nov 06, 2022 6:22 pm
Contact:

Re: Custom choice button per scene

#4 Post by sg27digital »

Thanks.
While ticlock's implementation does seem the nicest one - it did not work for me.
At first I got that button_width was unknown - so I defined it, then I got an error for using it as an argument.

So currently I'm using a mixture of both answers which is working for me. I also added in the linked solution so that I have:

screens.rpy:

Code: Select all

screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action xsize button_width


style choice_vbox is vbox
style choice_button is button
style choice_button_text is button_text

style choice_vbox:
    xalign 0.9
    ypos 700
    yanchor 0.5
    spacing gui.choice_spacing
My variables.rpy file (can be anywhere):

Code: Select all

default button_width = 700
default positiony = 700
default anchory = 0.5
init python:
    renpy.register_style_preference("choicepos", "normal", style.choice_vbox, "ypos", 700)
    renpy.register_style_preference("choicepos", "wide", style.choice_vbox, "ypos", 100)
    renpy.register_style_preference("choicepos", "normal", style.choice_vbox, "yanchor", 0.5)
    renpy.register_style_preference("choicepos", "wide", style.choice_vbox, "yanchor", 0)
My story file:

Code: Select all

$ button_width = 1700
$ renpy.set_style_preference("choicepos","wide")

menu:
	"1..."
		"answer"
	"2..."
		"answer"

$ button_width = 700
$ renpy.set_style_preference("choicepos","normal")

Note - my default button_width is 700 - not the usual 500

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Custom choice button per scene

#5 Post by _ticlock_ »

sg27digital wrote: Mon Nov 07, 2022 5:54 am While ticlock's implementation does seem the nicest one - it did not work for me.
You should not have problems with arguments in the choice menu unless you are using RenPy version 7.1 or below (8.x will work as well).
sg27digital wrote: Mon Nov 07, 2022 5:54 am At first I got that button_width was unknown - so I defined it, then I got an error for using it as an argument.
Note, that you should not define button_width, its default value can be defined in the choice screen:

Code: Select all

screen choice(items, button_width = 700):
sg27digital wrote: Mon Nov 07, 2022 5:54 am $ renpy.set_style_preference("choicepos","wide")
You can set the style using arguments. Check PyTom Cookbook for the choice menu with arguments for more details and ideashttps://patreon.renpy.org/menu-arguments.html:

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Custom choice button per scene

#6 Post by Ocelot »

Remember: style preferences are persistent and global.
If you go to your "wide" menu and quit the game and then load, all menus would be wide. If you load game made within "wide" menu while in "normal" mode, it will not be "wide" upon load.

Style preferences are for things like changing look of your game for accessebility, not gameplay purposes.
< < insert Rick Cook quote here > >

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Custom choice button per scene

#7 Post by _ticlock_ »

Using a choice menu with arguments you can set the style of the screen similarly as for button_width:

Code: Select all

screen choice(items, button_width = 700, choice_style = "normal"):
    style_prefix "choice"

    vbox:
        ypos (700 if choice_style == "normal" else 100)
        yanchor (0.5 if choice_style == "normal" else 0)
        
        for i in items:
            textbutton i.caption: 
                action i.action 
                xsize button_width
                

Post Reply

Who is online

Users browsing this forum: Bing [Bot]