Renpy.random help

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
Aliengraves
Newbie
Posts: 1
Joined: Wed Jan 26, 2022 8:10 pm
Tumblr: Aliengraveyards
Contact:

Renpy.random help

#1 Post by Aliengraves »

So, I preface this knowing how to make flags, menus, etc. I just looked into the renpy.random and how those work, but I am specifically looking into making a set of questions that can be randomized and chosen for a personality test.

To explain further, I am trying to figure out how to code these multi-choice options into randomized selections so that each time the player restarts the quiz there is a probability of a different question with answers that can result in one of three outcomes. For a better example, I am essentially trying to figure out the code to the quiz at the beginning of the pokemon mystery dungeon series, and applying that to renpy. Sorry if this is not well written, if there is some confusion I'm happy to explain further, but I would love some help :)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Renpy.random help

#2 Post by Ocelot »

So, I implemented (halfway) the quiz itself:

Code: Select all

# This is dictionary containing personality trait and their values
# As you can see, everythin is initialized to 0
default personality_traits = {
    "lonely": 0, "docile": 0, "quirky": 0, "brave"  : 0,
    "sassy" : 0, "calm"  : 0, "timid" : 0, "jolly"  : 0,
    "quiet" : 0, "hardy" : 0, "rash"  : 0, "hasty"  : 0,
    "bold"  : 0, "naive" : 0, "impish": 0, "relaxed": 0,
}

# This is a map of your highest personality trait and gender
# To the starter you get
define starter_map = {
    ("lonely", "male"): "Bulbasaur",  ("lonely", "female"): "Mudkip",
    ("docile", "male"): "Charmander", ("docile", "female"): "Bulbasaur",
    ("quirky", "male"): "Squirtle",   ("quirky", "female"): "Piplup",
    ("brave" , "male"): "Pikachu",    ("brave" , "female"): "Charmander",
    ("sassy" , "male"): "Meowth",     ("sassy" , "female"): "Totodile",
    ("calm"  , "male"): "Chikorita",  ("calm"  , "female"): "Cyndaquil",
    ("timid" , "male"): "Cyndaquil",  ("timid" , "female"): "Turtwig",
    ("jolly" , "male"): "Totodile",   ("jolly" , "female"): "Munchlax",
    ("quiet" , "male"): "Treecko",    ("quiet" , "female"): "Chikorita",
    ("hardy" , "male"): "Torchic",    ("hardy" , "female"): "Treecko",
    ("rash"  , "male"): "Mudkip",     ("rash"  , "female"): "Torchic",
    ("hasty" , "male"): "Skitty",     ("hasty" , "female"): "Pikachu",
    ("bold"  , "male"): "Turtwig",    ("bold"  , "female"): "Squirtle",
    ("naive" , "male"): "Chimchar",   ("naive" , "female"): "Skitty",
    ("impish", "male"): "Piplup",     ("impish", "female"): "Chimchar",
    ("relaxed","male"): "Munchlax",   ("relaxed","female"): "Meowth",
}

# This is the list [] if possible questions
# Each question is a tuple () of question text and a list [] of answers
# Each answer is a tuple () of answer text and dictionary {} of traits and values to add
default question_list = [
    ("Do you think that you might be a genius?",
        [
            ("Certainly!",          {"sassy":4, "naive":2, "jolly":2}),
            ("Well, not really...", {"hardy":2}                      ),
        ]
    ),
    ("Have you had any hobbies for a long time?",
        [
            ("Yes.", {"hardy":4}            ),
            ("No.",  {"quirky":4, "hasty":2}),
        ]
    ),
    ("Have you ever accidentally revealed a personal secret that someone shared with you?",
        [
            ("Yes.", {"rash":4, "lonely":4}),
            ("No.",  {"hardy":2}           ),
        ]
    ),
    ("Do you like to do things according to plan?",
        [
            ("Of course!",                {"hardy":4}           ),
            ("I'm not good at planning.", {"quirky":4, "rash":2}),
            ("Plans? Who needs plans?",   {"relaxed":4}         ),
        ]
    ),
    ("You have to move a heavy suitcase. What will you do?",
        [
            ("Carry it by myself.",      {"hardy":4, "brave":2}),
            ("Ask someone to help.",     {"docile":2}          ),
            ("Make someone else do it!", {"bold":4, "sassy":2} ),
        ]
    ),
    # As you can see, I didn't implement all questions
]

# This variable sets how many questions to ask. I set it to 3, instead of normal 8
# Because I didn't have enough questions
define question_limit = 3

label start:
    python:
        # Shuffle question list, so all questions are in random order
        renpy.random.shuffle(question_list)

        # Variable used to determine current question
        question_num = 0

    while question_num < question_limit:
        # Extract question we want to ask from list of questions
        $ current_question = question_list[question_num]
        $ question_num += 1
        # Ask question
        $ narrator("Question #[question_num]: " + current_question[0], interact=False)
        # Actually display menu and get answer
        # https://www.renpy.org/doc/html/statement_equivalents.html#renpy.display_menu
        $ result = renpy.display_menu(current_question[1])

        # Update personality values depending on answer
        python:
            for k, v in result.items():
                personality_traits[k] += v;

    menu:
        "What is your gender?"
        "Male":
            $ gender = "male"
        "Female":
            $ gender = "female"

    python:
        # Find trait with highest value in a map
        highest_trait = max(personality_traits, key=personality_traits.get)
        # Get starter using trait name and gender
        starter = starter_map[(highest_trait, gender)]
    "Your starter is: [starter]"

    return
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Andredron