Is there a simpler way to make multiple choices in a row?

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
User avatar
Mimic Fox
Newbie
Posts: 13
Joined: Wed Aug 05, 2020 8:52 pm
Contact:

Is there a simpler way to make multiple choices in a row?

#1 Post by Mimic Fox »

I'm currently making a mystery visual novel. At the end of each case the player will have to answer several questions in a row to come to a conclusion on what happened. Here's a simple example of how I'm doing these bits right now.

Code: Select all

    $ correct_answer_points = 0

    menu:
        "What was the murder weapon?"

        "Scissors":
            $ correct_answer_points += 0
            jump question2

        "Gun":
            $ correct_answer_points += 0
            jump question2


        "Knife":
            $ correct_answer_points += 1
            jump question2

    label question2:

    menu:
        "Who was the Murderer?"

        "Nozomi":
            $ correct_answer_points += 0
            jump final

        "Maki":
            $ correct_answer_points += 1
            jump final


        "Chika":
            $ correct_answer_points += 0
            jump final

    label final:

    if correct_answer_points == 2:

        "That's right!"

    else:
        "That's wrong!"
Is this a good way to do it? Is there a better/simpler way?

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Is there a simpler way to make multiple choices in a row?

#2 Post by IrinaLazareva »

Are you looking for a simpler solution or a more optimized one? I suppose your code is simple enough and does not require simplification.
There is a golden rule, if the code works, it's better not to touch it.

If it's about optimization. Then yes, there are ways.

For example, a menu statement already has a label. That is, the code:

Code: Select all

    label question2:

        menu:
can be replaced:

Code: Select all

    menu question2:
https://www.renpy.org/doc/html/menus.html#in-game-menus

And jump is unnecessary. The code:

Code: Select all

    menu:
        "What was the murder weapon?"

        "Scissors":
            $ correct_answer_points += 0
            jump question2

        "Gun":
            $ correct_answer_points += 0
            jump question2

        "Knife":
            $ correct_answer_points += 1
            jump question2

label question2:

    menu:
        "Who was the Murderer?"
is equivalent to:

Code: Select all

    menu:
        "What was the murder weapon?"

        "Scissors":
            $ correct_answer_points += 0

        "Gun":
            $ correct_answer_points += 0

        "Knife":
            $ correct_answer_points += 1

    menu question2:
        "Who was the Murderer?"
or

Code: Select all

    menu:
        "What was the murder weapon?"

        "Scissors":
            $ correct_answer_points += 0

        "Gun":
            $ correct_answer_points += 0

        "Knife":
            $ correct_answer_points += 1

    menu:
        "Who was the Murderer?"

User avatar
dGameBoy101b
Regular
Posts: 31
Joined: Sun Aug 12, 2018 8:32 am
itch: dgameboy101b
Contact:

Re: Is there a simpler way to make multiple choices in a row?

#3 Post by dGameBoy101b »

A more flexible way of storing the answers would be to use a list. This could allow you make more unique bad endings or easily change the correct answer later.

Code: Select all

$ response = []
menu:
    "What was the murder weapon?"
    "Scissors":
        $ response.append("scissors")
    "Gun":
        $ response.append("gun")
    "Knife":
        $ response.append("knife")
menu:
    "Who was the murderer?"
    "Nozomi":
        $ response.append("nozomi")
    "Maki":
        $ response.append("maki")
    "Chika":
        $ response.append("chika")
if response == ["knife", "maki"]:
    "Correct!"
elif response == ["knife", "nozomi"]:
    nozomi "You think I'd use that dinky little knife? Hah!"
else:
    "Wrong!"

Post Reply

Who is online

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