User input with different correct responses?

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
sonictoad
Regular
Posts: 30
Joined: Tue Mar 12, 2019 10:39 pm
Projects: It's Different When It's Your Own
Organization: Sonic Toad Media LLC
itch: nyhcmaven84
Location: Bronx, NY
Contact:

User input with different correct responses?

#1 Post by sonictoad » Thu Apr 23, 2020 6:51 pm

I'm having a hard time with the correct conditional for this. So, I have an easter egg in the game where different things can happen based on how the user answers one question. It's written like this:

Code: Select all

$ correctcolors = "red" and "blue" and "green"

$ colorguess= renpy.input("What color was it?")
    if colorguess== correctcolors :
        jump easteregg
    else:
        jump guessagain
When I tested this, it only recognized "red", not any of the other inputs. What am I doing wrong?

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: User input with different correct responses?

#2 Post by hell_oh_world » Thu Apr 23, 2020 10:17 pm

sonictoad wrote:
Thu Apr 23, 2020 6:51 pm
I'm having a hard time with the correct conditional for this. So, I have an easter egg in the game where different things can happen based on how the user answers one question. It's written like this:

Code: Select all

$ correctcolors = "red" and "blue" and "green"

$ colorguess= renpy.input("What color was it?")
    if colorguess== correctcolors :
        jump easteregg
    else:
        jump guessagain
When I tested this, it only recognized "red", not any of the other inputs. What am I doing wrong?

Code: Select all

$ correctcolors = ("red", "blue", "green")

$ colorguess= renpy.input("What color was it?")
    if colorguess in correctcolors :
        jump easteregg
    else:
        jump guessagain

User avatar
sonictoad
Regular
Posts: 30
Joined: Tue Mar 12, 2019 10:39 pm
Projects: It's Different When It's Your Own
Organization: Sonic Toad Media LLC
itch: nyhcmaven84
Location: Bronx, NY
Contact:

Re: User input with different correct responses?

#3 Post by sonictoad » Fri Apr 24, 2020 11:08 am

Tried that and it didn't work. Tried with both single quote (') and double quote (") in the parenthesis, also tried both == and "is", and in both cases it didn't recognize any input. With no parenthesis, it only recognizes the first string but not the others.
hell_oh_world wrote:
Thu Apr 23, 2020 10:17 pm
sonictoad wrote:
Thu Apr 23, 2020 6:51 pm
I'm having a hard time with the correct conditional for this. So, I have an easter egg in the game where different things can happen based on how the user answers one question. It's written like this:

Code: Select all

$ correctcolors = "red" and "blue" and "green"

$ colorguess= renpy.input("What color was it?")
    if colorguess== correctcolors :
        jump easteregg
    else:
        jump guessagain
When I tested this, it only recognized "red", not any of the other inputs. What am I doing wrong?

Code: Select all

$ correctcolors = ("red", "blue", "green")

$ colorguess= renpy.input("What color was it?")
    if colorguess in correctcolors :
        jump easteregg
    else:
        jump guessagain

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: User input with different correct responses?

#4 Post by hell_oh_world » Fri Apr 24, 2020 12:02 pm

sonictoad wrote:
Fri Apr 24, 2020 11:08 am
Tried that and it didn't work. Tried with both single quote (') and double quote (") in the parenthesis, also tried both == and "is", and in both cases it didn't recognize any input. With no parenthesis, it only recognizes the first string but not the others.
hell_oh_world wrote:
Thu Apr 23, 2020 10:17 pm
sonictoad wrote:
Thu Apr 23, 2020 6:51 pm
I'm having a hard time with the correct conditional for this. So, I have an easter egg in the game where different things can happen based on how the user answers one question. It's written like this:

Code: Select all

$ correctcolors = "red" and "blue" and "green"

$ colorguess= renpy.input("What color was it?")
    if colorguess== correctcolors :
        jump easteregg
    else:
        jump guessagain
When I tested this, it only recognized "red", not any of the other inputs. What am I doing wrong?

Code: Select all

$ correctcolors = ("red", "blue", "green")

$ colorguess= renpy.input("What color was it?")
    if colorguess in correctcolors :
        jump easteregg
    else:
        jump guessagain
What exactly are you trying to do? I just guessed that somehow you want to check whether the input is in the list of valid colors that can be guessed so that should work.

Code: Select all

define colors = ("red", "blue", "green")

label start:
	jump guess

label guess:
	$ guessed_color = renpy.input("What do you think is the color?")
	if guessed_color in colors: # the below code will run if the guessed color is in the defined colors, so if enter `red` this block will run, the color is case sensitive, it should be entered as how it was defined.
		"Wow! You got it right!"
		jump proceed
	else:
		"Oops! Wrong guess. Try again."
		jump guess

label proceed:
	pass
It's not really clear what you want. If that's not what you want to happen, then i suggest better explaining what you want to achieve with your previous code.
Note also that strings or what you call text in python, they don't actually care whether they're defined using a single quote or double quotations, 'abc' is very equal to "abc", there's no difference between the two.

User avatar
sonictoad
Regular
Posts: 30
Joined: Tue Mar 12, 2019 10:39 pm
Projects: It's Different When It's Your Own
Organization: Sonic Toad Media LLC
itch: nyhcmaven84
Location: Bronx, NY
Contact:

Re: User input with different correct responses?

#5 Post by sonictoad » Fri Apr 24, 2020 6:18 pm

Oh, I see what I got wrong! I didn't have my reading glasses on and mistook "in" for "is". Doh. Got it working now, thanks :D

Post Reply

Who is online

Users browsing this forum: mold.FF