Multiple password system.

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
erintesden
Newbie
Posts: 2
Joined: Sat May 30, 2020 4:37 pm
Contact:

Multiple password system.

#1 Post by erintesden »

Im trying to do this scene where a character tries to open a safe with an integrated IA, that accepts both numbers and letters for its password.

And its my intention to make so that you have the correct password that opens the safe, some specific wrong passwords that result in special dialogues, and a generic wrong password dialogue (else).

I found a similar old to what I wanted and tried to do it but it didnt worked. This is what I did:

Code: Select all

label start:

    "Okay, lets do it!"
    jump safe

label safe:

menu:
    "Try again.":
        jump code
    "No":
        return

label code:

$ pass1 = "3401"
$ pass2 = ("shit" "fuck")
$ pass3 = ("1234", "123456", "0000", "000000", "654321")
$ pass4 = "IA´S NAME"

$ code = renpy.input ("Input your answer.")

if code == pass1:
    "Correct Answer!"
    return

if code == pass2:
    "Wrong Answer. Try again!"
    jump safe

if code == pass3:
    "Language! Try again!"
    jump safe

if code == pass4:
    "Wrong Answer! But Im flattered! Try again!"
    jump safe

else:
    "Wrong Answer."
    jump safe


Thats it. I have tried to change some stuff around but the result is the same, the only option that works like it should is the "pass4", any of the other passwords always get me the dialogue of "else" variable. Not sure why

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Multiple password system.

#2 Post by rayminator »

some of your code is wrong

if code1
if code2
if code3
else ---- this else will go for the last if and ignored the rest

Code: Select all

if code == pass1:
    "Correct Answer!"
    return

elif code == pass2:
    "Wrong Answer. Try again!"
    jump safe

elif code == pass3:
    "Language! Try again!"
    jump safe

elif code == pass4:
    "Wrong Answer! But Im flattered! Try again!"
    jump safe

else:
    "Wrong Answer."
    jump safe
here is another password if you want to look at it
viewtopic.php?f=51&t=52536

User avatar
SONTSE
Regular
Posts: 98
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 11 VN's so far
Discord: jkx0282_10798
Contact:

Re: Multiple password system.

#3 Post by SONTSE »

if your answer is list of possible variants, you check it with 'in' instead of '=='

Code: Select all

if code in pass2:
    "Wrong Answer. Try again!"
    jump safe

if code in pass3:
    "Language! Try again!"
    jump safe

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Multiple password system.

#4 Post by rames44 »

Also, note that the use of parentheses creates a Python “tuple,” which is probably not what you want. You probably want a list (square brackets) or a set (curly braces).

Post Reply

Who is online

Users browsing this forum: SofyTrancy