Disable a Choice using conditional statement

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
Strobot
Newbie
Posts: 4
Joined: Fri Apr 27, 2018 11:04 pm
Contact:

Disable a Choice using conditional statement

#1 Post by Strobot »

hey guys here is a piece of code i have been writing fora part of my game

Code: Select all

label lbl_myroom_kitchen:
    scene bg bg_food_storage
    call screen scr_kitchen

screen food_storage_overlay:
    add "gui food_storage_beans_[beans]"
    add "gui food_storage_veg_[veg]"
    add "gui food_storage_meat_[meat]"


screen scr_kitchen:
    imagebutton auto "btn food_storage_cooking_%s" xpos 0 ypos 0 focus_mask True action Jump("lbl_food_storage_cooking")
    imagebutton auto "btn back_%s" xpos 0 ypos 0 focus_mask True action Jump("lbl_myroom")
    use food_storage_overlay

label lbl_food_storage_cooking:
    if beans == 0 and veg == 0 and meat == 0:
        pov "{i} I'm out of food"
        jump lbl_myroom_kitchen
    elif energy >= 10 or food <= 0:
        pov "{i}I'm not hungry"
        jump lbl_myroom_kitchen
    else:
        menu:
            "Beans(+1 Energy)":
                if beans == 0:
                    pass
                jump lbl_food_storage_beans
            "Veggie(+2 Energy)":
                jump lbl_food_storage_veg
            "Meat(+3 Energy)":
                jump lbl_food_storage_meat
            "Back":
                jump lbl_myroom_kitchen

label lbl_food_storage_beans:
    $ energy += 1
    show food_storage_cook_0 onlayer midlayer with dissolve
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    show food_storage_cook_2 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_2 onlayer abovemid
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    show food_storage_cook_2 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_2 onlayer abovemid
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    hide food_storage_cook_0 onlayer midlayer
    $ food -= 1
    $ beans -= 1
    if energy >= 10:
        $ energy = 10
    if beans <= 0:
        $ beans = 0
    if food <= 0:
        $ food = 0
    jump lbl_myroom_kitchen

label lbl_food_storage_veg:
    $ energy += 2
    show food_storage_cook_0 onlayer midlayer with dissolve
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    show food_storage_cook_2 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_2 onlayer abovemid
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    show food_storage_cook_2 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_2 onlayer abovemid
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    hide food_storage_cook_0 onlayer midlayer
    $ food -= 1
    $ veg -= 1
    if energy >= 10:
        $ energy = 10
    if veg <= 0:
        $ veg = 0
    if food <= 0:
        $ food = 0
    jump lbl_myroom_kitchen

label lbl_food_storage_meat:
    $ energy += 3
    show food_storage_cook_0 onlayer midlayer with dissolve
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    show food_storage_cook_2 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_2 onlayer abovemid
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    show food_storage_cook_2 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_2 onlayer abovemid
    show food_storage_cook_1 onlayer abovemid
    $ renpy.pause (0.5,hard=True)
    hide food_storage_cook_1 onlayer abovemid
    hide food_storage_cook_0 onlayer midlayer
    $ food -= 1
    $ meat -= 1
    if energy >= 10:
        $ energy = 10
    if meat <= 0:
        $ meat = 0
    if food <= 0:
        $ food = 0
    jump lbl_myroom_kitchen

I just want to disable "Beans(+1 Energy)" menu choice when $ beans = 0 i use the latest renpy for creating the game. Any help full tips on reshaping the code will be much appreciated, thanks in advance.

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: Disable a Choice using conditional statement

#2 Post by mitoky »

Wouldn't it work if you write

Code: Select all

menu:
    "Beans(+1 Energy)" if beans >= 1:
        "do something"
        jump continue_story 

Strobot
Newbie
Posts: 4
Joined: Fri Apr 27, 2018 11:04 pm
Contact:

Re: Disable a Choice using conditional statement

#3 Post by Strobot »

Yeah i thought of that like

Code: Select all

menu:
       "Beans(+1 Energy)" 
             if beans <= 0:
                   pov "{i}I'm out of beans"
                   jump lbl_myroom_kitchen
             else:
                   jump lbl_food_storage_beans
But that makes the player jump back lbl_myroom_kitchen every time he clicks the option when $ beans = 0,
So instead to i rather have that "Beans(+1 Energy)" it self disabled like the choice appears stagnant like it doesn't change color when hoverd over and does nothing when clicked on. I have seen this done in several renpy games, so i thought there may be a code just to disable this option
Removing or hiding the choice also might work nicely.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Disable a Choice using conditional statement

#4 Post by kivik »

Your code is not the same as mitoky's suggestion:

"Beans(+1 Energy)" if beans >= 1: only show this option if beans is 1 or above (disabled when beans is 0)
"Beans(+1 Energy)" if beans <= 0: only show this option if beans is 0 or below (enabled when beans is 0 or negative)

Post Reply

Who is online

Users browsing this forum: Google [Bot]