Changing Choice Menu Style WIth Flag

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
willyelektrix
Newbie
Posts: 12
Joined: Sun Aug 09, 2020 1:35 pm
Contact:

Changing Choice Menu Style WIth Flag

#1 Post by willyelektrix » Tue Apr 12, 2022 10:05 pm

Most of the choice menus in my game only have 2-3 options, and I have styled them in screens.rpy to look good with up to 3 options.

However, for one menu, I want to have 8 options. Is there a way I can style the choice menu screen to look different, but only in this one instance?

I tried including a flag right before the menu, and then using an if statement in screens.rpy, but it didn't seem to work (example below). It didn't cause an error, but it seems to always act as if the "multichoice" flag is False

Is there a way to do this?

Code: Select all

default multichoice = True

    menu :
Screens.rpy

Code: Select all

screen choice(items):
    style_prefix "choice"

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

## When this is true, menu captions will be spoken by the narrator. When false,
## menu captions will be displayed as empty buttons.
define config.narrator_menu = True

if multichoice : # For menu with more than 3 options.
    style choice_vbox1 is vbox
else :  # For menu with 3 or less options.
    style choice_vbox2 is vbox

style choice_button is button
style choice_button_text is button_text

style choice_vbox1:
    xalign 0.5
    ypos 920
    yanchor 0.5
    
    spacing gui.choice_spacing

style choice_vbox2:
    xalign 0.0
    ypos 0
    yanchor 0.0
    
    spacing gui.choice_spacing

style choice_button is default:
    properties gui.button_properties("choice_button")

style choice_button_text is default:
    properties gui.button_text_properties("choice_button")

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Changing Choice Menu Style WIth Flag

#2 Post by Imperf3kt » Wed Apr 13, 2022 12:30 am

You need to place the default outside any labels.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

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

Re: Changing Choice Menu Style WIth Flag

#3 Post by Ocelot » Wed Apr 13, 2022 3:43 am

Imperf3kt wrote:
Wed Apr 13, 2022 12:30 am
You need to place the default outside any labels.
That is actually not correct. You can have init block within label, you can have define/default within label, you can have screen definition within label. While it is not a good Idea to do so, you definetly can and it will work.

There are multiple problems here.

First one is the fact that style statements are executed during init time. The only time any conditional matters will be when game is starting.
Second is that both _vbox1 and _vbox2 would be unused, since there is nothing in the screen telling to use those styles.
Remove conditional from style definitions: make one a generic choice_vbox, and another choice_vbox_narrow. Then add a conditional to the screen itself:

Code: Select all

screen choice(items):
    style_prefix "choice"

    vbox:
        if len( items ) > 3: # You can use multichoice variable if you want to
            style_suffix "vbox_narrow"
        for i in items:
            textbutton i.caption action i.action
If you want to do some drastic changes, you can make second screen and use it instead of default:
menu (screen="my_new_screen"):
< < insert Rick Cook quote here > >

willyelektrix
Newbie
Posts: 12
Joined: Sun Aug 09, 2020 1:35 pm
Contact:

Re: Changing Choice Menu Style WIth Flag

#4 Post by willyelektrix » Thu Apr 14, 2022 9:09 pm

Ocelot wrote:
Wed Apr 13, 2022 3:43 am

Code: Select all

screen choice(items):
    style_prefix "choice"

    vbox:
        if len( items ) > 3: # You can use multichoice variable if you want to
            style_suffix "vbox_narrow"
        for i in items:
            textbutton i.caption action i.action
This did the trick! Thank you so much for your help. I understand the screens.rpy scripts a little better now too. Thanks again!

Post Reply

Who is online

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