Page 1 of 1

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

Posted: Mon May 17, 2021 9:32 am
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.

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

Posted: Mon May 17, 2021 9:44 am
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"]:

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

Posted: Mon May 17, 2021 10:14 am
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