Specific text input...?

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
Chorvaqueen
Regular
Posts: 109
Joined: Sun Sep 20, 2009 7:41 am
Projects: ID: Recollection
Location: Inverted Castle
Contact:

Specific text input...?

#1 Post by Chorvaqueen »

Is it possible to do this in Ren'Py?

You are asked to type in a text (not necessarily about naming yourself).

Then either two situations:

1.) It will be asking for specific words and if you enter wrong text, it will display an error note/message/image.
2.) Whatever you type will bring up random responses.

I'm not really a coding expert :|

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

Re: Specific text input...?

#2 Post by Alex »

As you can see http://www.renpy.org/wiki/renpy/doc/ref ... enpy.input, "input" function allows to set the value of a variable through keyboard input. So, later you can use this variable as you wish, for example - compare its value with predefined "secret word".

Code: Select all

label start:
    $ secret_pass = renpy.random.choice ("god", "sex", "secret")
    $ your_try = renpy.input ("Try to hack the secret password", "123")
    if your_try == secret_pass:
        "Yeeessss! We are in..."
    else:
        "Warning: wrong password!"
        jump start

Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Specific text input...?

#3 Post by Soraminako »

Alex wrote:As you can see http://www.renpy.org/wiki/renpy/doc/ref ... enpy.input, "input" function allows to set the value of a variable through keyboard input. So, later you can use this variable as you wish, for example - compare its value with predefined "secret word".

Code: Select all

label start:
    $ secret_pass = renpy.random.choice ("god", "sex", "secret")
    $ your_try = renpy.input ("Try to hack the secret password", "123")
    if your_try == secret_pass:
        "Yeeessss! We are in..."
    else:
        "Warning: wrong password!"
        jump start
That code seems like something that would be very fun and useful! :D Thank you for sharing it!

I tried to use it and had a problem though, any idea what might be messing up? ^^; Here's the traceback:
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script2.rpy", line 55, in script
$ secret_pass = renpy.random.choice ("god", "sex", "secret")
File "game/script2.rpy", line 55, in python
$ secret_pass = renpy.random.choice ("god", "sex", "secret")
TypeError: choice() takes exactly 2 arguments (4 given)
I used the code exactly the way you had it, so there shouldn't be 4 arguments, it's odd... :? When I tried using less words, it still continued having the same type of mistake.
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Specific text input...?

#4 Post by PyTom »

Choice takes a list, so write:

Code: Select all

$ secret_pass = renpy.random.choice (["god", "sex", "secret"])
Also, randomness like this may be a bad idea in game design, as it tends to restrict your users for little benefit.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Chorvaqueen
Regular
Posts: 109
Joined: Sun Sep 20, 2009 7:41 am
Projects: ID: Recollection
Location: Inverted Castle
Contact:

Re: Specific text input...?

#5 Post by Chorvaqueen »

Aw crap, I'm sorry about my first post I was so sleepy when I wrote this and I kinda forgot that I posted this.
Anyway, I also tried the code Alex posted then I suddenly realized that my first question was wrong in the first place.

Let me rephrase my query.

1.) Scenario: You need to type the password you got (plot-device maybe?).
2.) Scenario: Player tries to be a smartass and types certain words like fuck, or other cuss words and phrases or some iconic terms instead of the password. Player thinks there's something else so they do this.
3.) The system replies depending on the type of word player inputs. (Example: Typing "the answer to life the universe and everything" makes the system reply "42".)
4.) Typing any words outside the system's defined pool of specific words will yield a generic error message.
5.) Typing the real password will make you continue.

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Specific text input...?

#6 Post by KimiYoriBaka »

lol. I like your thinking here.

basically, what pytom pointed out is the reason why the old text parsing adventure games stopped being made. whenever you have a situation where the player can input whatever they want, it becomes a major hassle to try and guess the possibilities. this makes scenarios 2 and 3 unrealistic to do in renpy, as while python has more than enough capabilities to let you try this, the work involved won't be worth it.

for example, "the answer to life the universe and everything" is different from "the answer to life, the universe, and everything". Now, if you parse the text on a word by word basis, with each letter made forcibly lowercase, this isn't a problem. However, that still assuming the words are in a certain order and spelled correctly. (if you've ever played king's quest 1 and tried spelling rumplestiltskin, you'll understand)

If you still want to try, here's how:

you can use renpy.input() like in alex's example, but in a loop. The password should be defined beforehand, of course. For checking the password, you can just compare the text to the password as you would any value, as long as the player knows to be exact with it. Then, if it isn't correct you check it with any number of possibilities that you want to include, before then looping.

a possible example:

Code: Select all

label start:
    $ password = "12345, what a stupid code."
    "The password is \"12345, what a stupid code.\""
    "Remember to put it in exactly as it's written."
    jump codereader

label codereader:
    input = renpy.input("What is the password")
    if input == password:
        jump continuation
    python:
        input = lower(input)
        parsed = ""
        wordlist = []
        for s in input:
            if isalpha(s) or isdigit(s):
               parsed = parsed + s
            else:
               wordlist.append(parsed)
        if parsed:
            wordlist.append(parsed)
    if "fuck" in wordlist or "shit" in wordlist or "damn" in wordlist:
        "Your language is not appreciated"
        jump codereader
    if "answer" in wordlist and "life" in wordlist and "universe" in wordlist and "everything" in wordlist":
        "42"
        jump codereader
    "That is not the password"
    jump codereader
disclaimer: I haven't actually tested this code...

GROWLEX
Newbie
Posts: 4
Joined: Fri May 27, 2016 10:13 pm
Projects: Tale of Edwin Richbow
Organization: Growlex
Skype: TheCraizyGamer
Soundcloud: GROWLEX_Music
Contact:

Re: Specific text input...?

#7 Post by GROWLEX »

My game has code like this to activate character outfits and VIP endings. Here is what I wrote down.

Code: Select all

#This is where you put the codes.
$ password1 = "TheMuzzaFuzinVIP"
$ password2 = "we are anonymous"
$ password3 = "Talk dirty to me"

#This is where it askes you for a code.
"Do you have a code?"

menu:
    #If you say yes, it will ask you to input a string of characters.
    "Yes":
        $ code = renpy.input ("Input your code here.")
        jump check_for_code
    "No":
        "Are you sure?"
        menu:
            "Yes":
                jump loading
            "No":
                jump start
                
#This is the verification step. Here we don't want to put an else
#function in between, because it will result in a wrong code if code 2 is put in.
label check_for_code:
    if code == password1:
        "You have recieved the VIP endings."
        $ WC = 0
        $ VIP = True
        jump other_codes
    if code == password2:
        "You have unlocked an outfit."
        $ WC = 0
        $ Anonymous_Outfit = True
        jump other_codes
    if code == password3:
        $ WC = 0
        $ Dirty = True
        "You have unlocked special dialect."
    else:
        jump wrong_code
        
#This is where you are directed if you have a wrong code.
label wrong_code:
    "Wrong code!"
    
    #Here you will get a point added to your failed attempts.
    #If you get to 3, you will be directed to the loading screen.
    if WC <= 3:
        "You have reached the maximum attempts."
        jump loading
    else:
        jump next
    label next:
    $ WC += 1
    jump start
label other_codes:
    "Do you have any other codes?"
    menu:
        "Yes":
            jump start
        "No":
            jump loading
I have tested this code, and it will be in my new game.

BigMo
Newbie
Posts: 1
Joined: Tue Feb 27, 2018 4:33 pm
Contact:

Re: Specific text input...?

#8 Post by BigMo »

:?: hey, i want to be able to check if a users input is equal to a string and if not, check if it is equal to another string so on and so forth.


for example:
label start:
command = renpy.input("Command: ")
# here i check if the input is equal to "open the mailbox" and if not i want to be able to check if it is equal to "take the mailbox".


how do i do this????

thanks for the help,
BigMo

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

Re: Specific text input...?

#9 Post by Alex »

Try something like

Code: Select all

label start:
    $ command = renpy.input("Command: ")
    if command == "open the mailbox":
        "You've opened the mail box - there were mail inside it, mmm..."
    elif command == "take the mailbox":
        "You've tried to take the mailbox, but it was too heavy for you. So, you just kicked it."
    else:
        "{i}~What?~{/i}"
        jump start
    "Game over."
https://www.renpy.org/doc/html/text.html#text-tag-i
https://www.renpy.org/doc/html/quicksta ... statements

Post Reply

Who is online

Users browsing this forum: Google [Bot]