Help with a code for user-input answers?

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
Juno
Regular
Posts: 56
Joined: Sat Mar 14, 2015 6:41 am
Contact:

Help with a code for user-input answers?

#1 Post by Juno »

I've searched far and wide for a simple way to do this, but to no avail. I feel like this shouldn't be difficult to do on Ren'Py, although I have little experience coding.

I have two weeks until I take a placement test at my school and instead of using flashcards, I wanted something where it could give me a word or words, then I could fill in the user input blank with the answer. I can either get it right, or wrong. If I get it wrong, it could just give me the correct word and move on. If I get it right, it moves on. Nothing complicated.

Not all answers need to be on the same screen. It could be flashcard-like. I just would prefer to type out my answers as opposed to selecting them from a list of options. Something like this:
dumbgif.gif
Is this possible, and easy to do? Thanks for any help.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Help with a code for user-input answers?

#2 Post by PyTom »

Code: Select all


label start:
    $ questions = [
        ("What is the answer to the great question of life, the universe, and everything?", "42"),
        ("How much wood could a woodchuck chuck if a woodchuck could chuck wood?", "42kg/day"),
        ("What is 43 minus 1?", "42"),
       ]


    $ renpy.random.shuffle(questions)

    while questions:
        $ q, a = questions.pop()

        $ answer = renpy.input(q)
        if answer == a:
            "That's right!"
        else:
            "Wrong. The right answer is [a]."

    "Done."
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Juno
Regular
Posts: 56
Joined: Sat Mar 14, 2015 6:41 am
Contact:

Re: Help with a code for user-input answers?

#3 Post by Juno »

Thank you so much! <3

That's exactly what I need.

Post Reply

Who is online

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