Problem relating to input name[SOLVED]

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
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Problem relating to input name[SOLVED]

#1 Post by AsHLeX » Sat Jan 10, 2015 8:06 am

How do I put this... It's like after the character input his/her name, I want to ask them "What is your name?" again just for fun... But for some reason, even if I type the exact same thing, it still registers as "WRONG" (incorrect).

Xavimat's code:

Code: Select all

# Reply and Reply2
# by xavimat (cc-by, 2013)
# inspired by fiorica's "The Doll's Stories" and SusanTheCat's "Thera'Py"
# improved with help of jw2pfd

init python:

    def reply(question = "Yes or no?",
        answers = "yes,no",
        invalid_character = None,
        invalid_answer = "(Invalid answer)",
        show_answers = False):

        thequestion = question
        found_it = ""
        ans = answers.replace(" ", "")
        ans = ans.split(",")
                       
        if show_answers:
            thequestion += " {size=-10}("
       
            for element in ans:
                thequestion += element + ', '
            thequestion = thequestion[:-2] + "){/size}"           
       
        while found_it == "":
           
            phrase = renpy.input(thequestion)
            phrase = phrase.lower()       

            for chara in ',.;:!?-+*()[]{}&%$':
                phrase = phrase.replace(chara, ' ')           
            phras = phrase.split()
       
            for element in ans:
                for theword in phras:
                    if found_it == '' and element == theword:
                        found_it = element
                       
            if found_it == "":
                found_it = "WRONG"

        return found_it
Input name (1st time):

Code: Select all

label naming:
        $ player_name = renpy.input("What is my name?")
        $ player_name = player_name.strip()
        if player_name == "":
            jump naming
        else:
            play sound "pong.wav"
            hide you
How I used it:

Code: Select all

"Note: Input your name in the EXACT form that you entered in the beginning."
            $ r = reply("What is your name?", "[player_name]")
            if r == "[player_name]":
                $ Kyo += 1
                show kyo smile
                kyo "*laughs* Sorry, sorry. {w}I was just kidding with you."
            elif r == "WRONG":
                $ renpy.block_rollback()
                show kyo urgh
                kyo "... ..."
Like for example, if I keyed in my name as "AsHLeX" the first time, and the second time I did the same thing, for some reason Kyo still goes "... ...".
I don't know where I went wrong...
*Completely lost now*
Thank you so much for reading this/replying!
Last edited by AsHLeX on Sun Jan 11, 2015 3:14 am, edited 1 time in total.
Image

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Problem relating to input name

#2 Post by philat » Sat Jan 10, 2015 12:13 pm

I haven't bothered to look through the code very closely, but for what you're trying to accomplish, is there a point to using that code as opposed to just taking another input (say, player_name_2) and checking it against player_name?

User avatar
mjshi
Regular
Posts: 179
Joined: Wed Mar 13, 2013 9:55 pm
Completed: MazeSite01, Ponderings of Time
Contact:

Re: Problem relating to input name

#3 Post by mjshi » Sat Jan 10, 2015 1:00 pm

Basically what philat was saying, but here's a concrete example--

Code: Select all

init:
    $ playername = "Charlie"
    $ name_check = None


c = DynamicCharacter("playername")

label start:
  
    $ playername = renpy.input("Please input your name!", default="Charlie")
    
    "Hm, why don't you input your name again?"
    
    $ name_check = renpy.input("Again@")
    
    if playername == name_check:
        
        "So your name is [playername], right?"
        
    else:
        
        "Is your name [playername] or [name_check]?!?"

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Problem relating to input name

#4 Post by AsHLeX » Sun Jan 11, 2015 3:13 am

Okay, got it. Thanks!!!! :)
You guys really saved me there ^^"
Image

User avatar
xavimat
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Problem relating to input name[SOLVED]

#5 Post by xavimat » Sun Jan 11, 2015 12:38 pm

I agree with philat ans mjshi. What you need is another input to check if they match.

On the other hand, here is the reason your initial code doesn't work:
First: You use the variable player_name inside "[]" when it's not needed, and I suspect there is some problem here. There are two lines that must be:

Code: Select all

$ r = reply("What is your name?", player_name)
if r == player_name:
Second: The reply() function offers more playability. It expects the user to enter some text (like "Why are you asking me again. I've said you already that my name is AsHLeX!")
But, to avoid problems with case, the function lowers the answer given by the user. It doesn't lower the "possible answers" because it expects the developer to put them in lowercase.
In your case, you don't want to change the "case", the you can delete the line:

Code: Select all

phrase = phrase.lower()
With this two changes, the code should work. But, as we've said, maybe is not what you need here.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Problem relating to input name[SOLVED]

#6 Post by AsHLeX » Sun Jan 11, 2015 6:39 pm

@xavimat:
Got it, thanks loads! :)
Image

Post Reply

Who is online

Users browsing this forum: No registered users