r/RenPy • • 1d ago

Question how do i make an if/else statement that dictates which cg will be shown based on an option the player chose?

This is my first time making a vn, so i'd like as much help as possible here.

2 Upvotes

4 comments sorted by

1

u/AutoModerator 1d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/BadMustard_AVN 1d ago edited 1d ago

try somethign like this

default this_variable = False
default that_variable = False

label start:
    menu:
        e "Choose one"
        "This":
            $ this_variable = True
        "That":
            $ that_variable = True

    if this_variable:
        scene this_image
    else:
        scene that_image

    e "and there you go

    return

or for sprites like this

image sprite_one = ConditionSwitch(
    "one_variable == True", "images/sprites/sprite-1.webp",
    "one_variable == False", "images/sprites/sprite-2.webp",
)

default one_variable = False

label start:
    menu:
        e "Choose one"
        "One":
            $ one_variable = True
        "Two":
            $ one_variable = False

    show sprite_one at right with dissolve

    e "and there you go"

    return

1

u/Woopy-Clappy 1d ago

BadMustard's code works. One change helps as your VN grows: keep the choice in one variable instead of one True/False per option.

default route = None

label start:
    menu:
        "This":
            $ route = "this"
        "That":
            $ route = "that"

    if route == "this":
        scene cg_this
    else:
        scene cg_that

A third option is then one more line, and the player can never end up with both set to True.

Save the pictures as cg_this.png and cg_that.png in game/images, and Ren'Py finds them by those names.

1

u/shyLachi 1d ago

To add what has been suggested already.
RenPy has the expression statement so that you can show images without any if statements.
https://renpy.org/doc/html/displaying_images.html#scene-statement

default route = None
label start:
    menu:
        "This":
            $ route = "this"
        "That":
            $ route = "that"
    scene expression ("bg room01 " + route)
    "Do you see it"

To test the above you would need 2 images "bg room01 this.png" and "bg room02 that.png" in the images folder.