One variable with multiple attributes (I want an input check where multiple answers are correct) [SOLVED]

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
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

One variable with multiple attributes (I want an input check where multiple answers are correct) [SOLVED]

#1 Post by MoonByte »

I lack the programming vocabulary so sorry if the title sounds confusing, but the idea is basically this:

I ask for a password. I give them the correct answer. Later they have to put in the answer.
My dilemma is now this:
People might use like 15 ways to write the password in regard to upper and lower case and I just want one neat line of options and have the game check that one line.
Something that looks like this:

Code: Select all

define e = Character("Eileen")
default password = ("crazy time", "Crazy Time", "CRAZY TIME", "Crazy time", "crazy Time")

label start:
    $ code = renpy.input ("What time is it?")
    if code == password:
        jump right_code_white
    else:
        jump wrong_code_white

label right_code_white:
    e "This was correct."
    return

label wrong_code_white:
    e "This was wrong."
    jump start
This specific one doesn't work.
I looked up if you can make Renpy case-insensitive and the answer seems to be no, so I need to specify all the different variations of this answer somehow.
I tried to look here and on google for an answer, but almost all replies are about character names or stuff where the answers are NOT essentially identical (like, if you type in jokes, you get a different reaction which is not what I want. There is only right or wrong). I assume maybe there is a thread out there with my answer, but I have no idea what the words to find it are.
But I DO assume that there is probably a way to assign multiple answers to a condition/string/variable/whatever those are called.

I KNOW that I could just do this and be "done" with it, but ugh, it looks so...horrible and frankly, it looks unnecessarily complicated.

Code: Select all

default password1 = "crazy time"
default password2 = "Crazy Time"
default password3 = "CRAZY TIME"
default password4 = "Crazy time"
default password5 = "crazy Time"
default password6 = "CrAzY tImE"
default password7 = "cRaZy TiMe"

label start:
    $ code = renpy.input ("What time is it?")
    if code == password1:
        jump right_code_white
    elif code == password2:
        jump right_code_white
    elif code == password3:
        jump right_code_white
    elif code == password4:
        jump right_code_white
    elif code == password5:
        jump right_code_white
    elif code == password6:
        jump right_code_white
    elif code == password7:
        jump right_code_white
    else:
        jump wrong_code_white
Like, sure, I do the latter if I am wrong and there is no alternative, but I want to hope there IS a way to just string all options together into one variable and do ONE If-check instead of 12.
Last edited by MoonByte on Mon May 17, 2021 10:14 am, edited 1 time in total.

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

Re: One variable with multiple attributes (I want an input check where multiple answers are correct)

#2 Post by Ocelot »

Step 1: force input by user to specific case:
$ code = code.lower()
Step 2: look up password in list of all still possible variations:
if code in ["crazy time", "crazy-time", "crazytime", "idonthavetimeforthis"]:
< < insert Rick Cook quote here > >

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: One variable with multiple attributes (I want an input check where multiple answers are correct)

#3 Post by MoonByte »

Thanks, Ocelot, it works!

Code: Select all

$ code = renpy.input ("Well? What time is it?")
$ code = code.lower()
if code in ["crazy time", "crazy-time", "crazytime", "idonthavetimeforthis"]:
	jump right_code_white
else:
        jump wrong_code_white

Post Reply

Who is online

Users browsing this forum: decocloud, Ocelot