Having some menu choices hidden, others greyed out

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
Nephthys
Newbie
Posts: 17
Joined: Sun Jan 19, 2014 4:51 pm
Contact:

Having some menu choices hidden, others greyed out

#1 Post by Nephthys »

So I'm aware that you can set:

Code: Select all

define config.menu_include_disabled = True
to toggle whether menu choices that don't meet requirements are hidden from view, or greyed out. However, ideally I'd like to decide choice by choice, whether that choice should be hidden or greyed out? Consider this script:

Code: Select all

default button_presses = 0

label choice_test:
    menu():
        "How many times can you press the button? [button_presses] times pressed so far."
        
        "Press the button.":
            "You press the button!"
            $button_presses++
            jump choice_test
            
        # I want this choice to be greyed out but visible, so the player knows
        # if they press the button ten times, they will win a stuffed bunny.
        "Collect the ten-button-press prize." if button_presses >= 10:
            "You win a stuffed bunny!"
            jump choice_test
            
        # I want this choice to be invisible until the condition is met, so that
        # the player does *not* know that they can win an orangutan if they
        # keep pressing the button.
        "Collect the hundred-button-press prize." if button_presses >= 100:
           "Oh wow, you have won a live orangutan!"
           jump choice_test
I've searched around a fair bit, and I know you can hide menu choices automatically after they've been activated using 'set', for preventing coming back to a dialogue, and this does appear to be compatible with menu_include_disabled, but I can't see a way that would allow me to actively hide/unhide menu choices independently from greying them out.

I think I can maybe see how I could do this by editing screens.rpy? If I were to attach some special string to menu item.caption, I could maybe skip drawing that particular menuitem, but this seems overly convoluted. Does there exist any more elegant way? I would love to be able to just add some flag to the menu choice that would specify whether it gets hidden when disabled or not.

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

Re: Having some menu choices hidden, others greyed out

#2 Post by _ticlock_ »

Nephthys wrote: Fri Apr 14, 2023 11:27 am
You can slightly change the choice screen and use item arguments: For example:

Code: Select all

define config.menu_include_disabled = False
in screens.rpy

Code: Select all

screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                sensitive i.kwargs.get("sensitive", True)
                action i.action

Code: Select all

default button_presses = 0

label choice_test:
    menu():
        "How many times can you press the button? [button_presses] times pressed so far."
        
        "Press the button.":
            "You press the button!"
            $ button_presses += 1
            jump choice_test
            
        "Collect the ten-button-press prize." (sensitive = (button_presses >= 10)):
            "You win a stuffed bunny!"
            jump choice_test
            
        "Collect the hundred-button-press prize." if button_presses >= 100:
           "Oh wow, you have won a live orangutan!"
           jump choice_test
PS: button_presses++ does not work in python

Nephthys
Newbie
Posts: 17
Joined: Sun Jan 19, 2014 4:51 pm
Contact:

Re: Having some menu choices hidden, others greyed out

#3 Post by Nephthys »

Thank you that's a great solve, definitely works like a charm!

I had a feeling that it seemed like I could pass values from the choices down to Python like that, but I still can't for the life of me work out how Ren'Py code translates to a more standard function/argument format. Being able to pass arbitrary keyword arguments like this down to the screen code definitely opens up possibilities :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]