[SOLVED]Formatting individual choice menu options based on variable

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
NeilTylerFloyd
Newbie
Posts: 5
Joined: Thu Mar 10, 2022 7:19 pm
Completed: Blood Bath & Beyond, Worthless Dirt Boys
Location: Chicago, IL
Contact:

[SOLVED]Formatting individual choice menu options based on variable

#1 Post by NeilTylerFloyd »

Hi everyone! I'm making my first visual novel in Ren'Py and would really appreciate some help on customizing choice menu options based variables.

What I'm trying to do is have choices locked behind variable checks. That is pretty simple on its face, and I'm familiar with the way that's built into ren'py. The issue, though, is that I want to tell players WHY the choice is showing but not selectable. As far as I understand it, the native Ren'Py way to do it does not do anything but show the option and make it unselectable.

Ideally, my game's choice menu would show all possible options. Options that the player does not have the appropriate stats/flags for would be in red text. These red buttons could still be clicked, though, and get a message telling them why they can't do it in the dialogue box.

I have figured out a rather inelegant way to do this. It's not scalable and requires a lot of custom and redundant coding when multiple gated choices are involved. Here is what that looks like:

Code: Select all

if test_variable < 20:
        menu test_choice:
            "What do you do?"

            "Eat some sushi":
                jump test_choice_sushi

            "Go for a walk":
                jump test_choice_walk

            "{color=#FF0000}Punch the moon{/color}":
                 "I don't have a high enough TEST VARIABLE to do that!"
                 jump test_choice


    else:
        menu test_choice_a:
            "What do you do?"

            "Eat some sushi":
                jump test_choice_sushi

            "Go for a walk":
                jump test_choice_walk

            "{color=#3CB043}Punch the moon{/color}":
                 jump test_choice_moon

label test_choice_sushi:

    "You eat sushi."

    jump locked_choice_tester_2

label test_choice_walk:

    "You go for a walk."

    jump locked_choice_tester_2

label test_choice_moon:

    "You punch the moon. Sick."

    jump locked_choice_tester_2
    
    
My humble ask to all you brilliant Ren'Py wizards on this forum is: How can I conditionally format INDIVIDUAL menu choices without making multiple menus with different formatting as in my code above? PyTom told me I'd probably have to do custom menus with arguments passed to the choices. I have no idea how to do this. Either way, I'm sure there's a solution that's cleaner and more scalable than what I have here.

Any help would be greatly appreciated!
Last edited by NeilTylerFloyd on Fri Jun 24, 2022 12:58 pm, edited 1 time in total.

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Formatting individual choice menu options based on variable

#2 Post by strayerror »

You can do it this way, which still has a little duplication, but at least you're not duplicating entire menus, only those bits where you need the difference. There are other ways to do this with even less duplication but they're far more complex and very unlikely to be worth it in this scenario.

Code: Select all

menu test_choice:
    "What do you do?"

    "Eat some sushi":
        jump test_choice_sushi

    "Go for a walk":
        jump test_choice_walk

    "{color=#FF0000}Punch the moon{/color}" if test_variable < 20:
        "I don't have a high enough TEST VARIABLE to do that!"
        jump test_choice
                 
    "{color=#3CB043}Punch the moon{/color}" if test_variable >= 20:
         jump test_choice_moon

NeilTylerFloyd
Newbie
Posts: 5
Joined: Thu Mar 10, 2022 7:19 pm
Completed: Blood Bath & Beyond, Worthless Dirt Boys
Location: Chicago, IL
Contact:

Re: Formatting individual choice menu options based on variable

#3 Post by NeilTylerFloyd »

Thanks for the reply, strayerror! I didn't even think to mess with the config.menu_include_disabled after I had turned it True months ago. Your idea is already going to save me a ton of work, and since my coding skills are close to nil I probably won't even mess with the more complicated solutions. Cheers mate!

User avatar
m_from_space
Miko-Class Veteran
Posts: 950
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: [SOLVED]Formatting individual choice menu options based on variable

#4 Post by m_from_space »

You could also pass the color as an argument to the choice screen, if you plan on doing that often. For that you need to alter "screen choice(items)" inside screens.rpy. Doing that you could write something like:

Code: Select all

menu:
    "What color do you like?"
    "Red" ('#f00'):
        jump bloodbath
    "Green" ('#0f0') if test_variable < 20:
        jump forest
    "Blue" ('#00f') if test_variable >= 20:
        jump sky
The screen should then look something like this:

Code: Select all

screen choice(items):
     for i in items:
         textbutton i.caption:
             action i.action
             if i.args:
                 text_color i.args[0]

Post Reply

Who is online

Users browsing this forum: No registered users