How to reset input value

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
MrRogerSmith
Regular
Posts: 42
Joined: Fri Jan 21, 2022 8:58 pm
Projects: Leaving DNA
itch: impiousmonk
Contact:

How to reset input value

#1 Post by MrRogerSmith »

Hello all. In my murder investigation game, I am trying to create a sequence where the player can identify a clue and unlock additional dialogue. Here's my code:

Code: Select all

label clay_art:
    menu:
        "Comment on something I notice about the apartment":
            $ noart = renpy.input("What should I comment on?", length = 15).strip()
            if noart == "no art" or "no artwork" or "bare walls" or "empty walls" or "no paintings":
                $ clay_art = True
                mc "Are you an art connoisseur?"
                mc "I don't really see any artwork on your walls."
                hc "No, like I said, I just fiddled around with it a bit when I was younger."
                mc "Do you own art supplies?"
                hc "No.  No, that was years ago."
                pass
            else:
                mc "Hmm, I don't think that would be helpful."
                jump clay_art
        "I don't notice anything about the apartment":
            $ clay_art = False
            pass
Now, let's say the player enters "no art" for the input. That correct answer obviously takes him/her through to the dialogue that follows. But let's say that the same player has already done that, and then they want to replay the sequence and put in "dogs," which is not a correct response. Under this code, the player will still advance to the dialogue triggered by inputting a correct answer, presumably because the correct answer has already been stored by Renpy and entering an incorrect answer doesn't reset that.

Is there a way for me to reset that value so a player can change their response?

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

Re: How to reset input value

#2 Post by Ocelot »

You just need to overwrite value contained in it with osme other value. As you intend to store user input in it, the easies way is to overwrite it directly with input:
[c$ noart = input(...[/c].
You might notice that it is exactly what you wrote in your code. Well, yes. There are no mysterious "previous values" plaguing you. In fact, if you run it first time and choose "dogs" as your first ever response, you will still go to the "no art" branch.

The problem is in your condition:

Code: Select all

if noart == "no art" or "no artwork" or "bare walls" or "empty walls" or "no paintings":
Having to juggle several programming languages and sibtle differences in some areas between them often make me paranoid about operator order. To keep my sanity, I often use parentheses to ensure operation order is always correct. In your case, I will use them to show operaton order:

Code: Select all

if (noart == "no art") or ("no artwork") or ("bare walls") or ("empty walls") or ("no paintings"):
That's better. Now consider what happens if you ented "dogs":
First noart == "no art" is evaluated. noart is set to "dogs", which is not equal to "no art", so it evaluates to False.
Second "no artwork" is evaluated. As any non-empty container does, itevaluates to True.
As we all know if any operand in seqence of "or"s is True, whole expression is True. So that branch is chosen.

How to fix it? Well, you can explicitely compare each string: if noart == "no art" or noart == "no artwork" or ..., but that is long and repetitive. Instead you can check if variable is in some container:

Code: Select all

if noart in ("no art", "no artwork", "bare walls", "empty walls", "no paintings"):
< < insert Rick Cook quote here > >

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to reset input value

#3 Post by Alex »

MrRogerSmith wrote: Sat Sep 17, 2022 3:54 pm ...

Code: Select all

if noart == "no art" or "no artwork" or "bare walls" or "empty walls" or "no paintings":
...
I suspect that problem is in this line - the condition is incorrect.
if noart == "no art" or "no artwork" will be true if ('noart' is equal to 'no art') is True or 'no artwork' is True. The last is always true, so your condition is always true.

Try it like

Code: Select all

if noart == "no art" or noart == "no artwork" or noart == "bare walls" or noart == "empty walls" or noart == "no paintings":
or

Code: Select all

if noart in ["no art", "no artwork", "bare walls", "empty walls", "no paintings"]:
edit: oops...

MrRogerSmith
Regular
Posts: 42
Joined: Fri Jan 21, 2022 8:58 pm
Projects: Leaving DNA
itch: impiousmonk
Contact:

Re: How to reset input value

#4 Post by MrRogerSmith »

Thank you, both! The code is now doing exactly what I wanted. I very much appreciate the responses.

Post Reply

Who is online

Users browsing this forum: Google [Bot]