Writing answers instead of choosing menu options [EDITED]

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Writing answers instead of choosing menu options

#31 Post by jw2pfd » Tue Aug 13, 2013 6:05 am

Hello all,

I have been away from these forums for quite awhile now and was interested in coming across this thread. I worked on the code for fioricca's "The Dolls' Stories" and I even received a PM from TrickWithAKnife at one point with interest in the chat system that the game uses and I do apologize for not replying to that Trick. Around that time, there were various reasons that pulled me away from coding and I wasn't able to finish "The Dolls' Stories" project mostly due to delays. I am not sure whether any code for the game was edited between my exit on that project and its release.

Unfortunately, my code from the game isn't entirely portable for generic use. I designed it with specifics of "The Dolls' Stories" in mind and I used quite a bit of classes. Lack of planning mostly led to my classes becoming more and more disorganized as the project went on. I also wasn't as familiarized with all of the functions available in Python and I didn't even know str.split() existed until I read the original post of this thread! I made my own class to parse the input and create a list which is rather inefficient in hindsight.

Depending on all the features you want in a chat system, the complexity can vary so much. Code does benefit from using classes based on complexity and the amount of features added, but the code in the original post seems more than efficient at achieving text input without being too esoteric. The post with the code that used the dictionary data type for synonyms seems like a decent approach as well. My entrance into this thread seems way after the fact and I am not sure how much interest or need there is for expanding what has already been posted. If I manage to stay active on these forums, then I will keep my eye on this thread and hopefully add to any future discussion.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
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: xavimat
Location: Italy
Contact:

Re: Writing answers instead of choosing menu options

#32 Post by xavimat » Wed Aug 14, 2013 10:06 am

Kokoro Hane wrote:This code is very useful! I am making a mock-up Internet function in Eileen's (Otome) Love Story, and this code was PERFECT for the "Search" function, that way users can type in keywords. ^.^
Currently, the code only returns the first keyword found. If you need a function able to return more than one keyword, tell me; I can do it.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Writing answers instead of choosing menu options

#33 Post by jw2pfd » Wed Aug 14, 2013 7:57 pm

I was toying around with your code and I had a suggestion for a potential improvement. It really is just preference as all it does is increase what I consider to be user-friendliness. Instead of having the user entering a list on the front end of the call for answers, you could allow the user to enter it into a string format with answers separated by commas to be parsed/split on the back end. Turning a function call from:

Code: Select all

$ r = reply("Where do you want to go?", ["park","beach","home"], e, "Can you repeat your answer, please?")
Into:

Code: Select all

$ r = reply("Where do you want to go?", "park,beach,home", e, "Can you repeat your answer, please?")
Not much code would have to be changed on the back end. It can be changed to:

Code: Select all

# Reply
# by xavimat (cc-by, 2013)
# inspired by fiorica's "The Doll's Stories" and SusanTheCat's "Thera'Py"

init python:
   
    def reply(question = "Yes or no?",
        answers = "yes,no",                           #default parameter is now a string instead of list
        invalid_character = None,
        invalid_answer = "(Invalid answer)",
        show_answers = True):
       
        thequestion = question       
        ans = answers.split(',')                       #split the string to be stored in ans as a list

        if show_answers:
            thequestion += " {size=-10}("
            for element in ans:                        #ans list
                thequestion += element + ', '
            thequestion = thequestion[:-2] + "){/size}"           
        phrase = renpy.input(thequestion)
        phrase = phrase.lower()       

        for chara in ',.;:!?-+*()[]{}&%$':
            phrase = phrase.replace(chara, ' ')           
        phras = phrase.split()       
        found_it = ''
        for element in ans:                           #ans list
            for theword in phras:
                if found_it == '' and element == theword:
                    found_it = element     
             
        while found_it == '':
            renpy.say(invalid_character, invalid_answer)
            found_it = reply(question, answers, invalid_character, invalid_answer, show_answers)           
           
        return found_it
Also, additional toying with the code, I removed the recursive call. This has its benefits. The code including the change above is:

Code: Select all

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

        thequestion = question or self.Question()
        found_it = ''
        ans = answers.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 == '':
                renpy.say(invalid_character, invalid_answer)

        return found_it
Of course, a change like this really doesn't matter all that much. The first change though of allowing string entry for answers over the list entry I consider to be more user-friendly. These are just suggestions and feel free to completely ignore them.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
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: xavimat
Location: Italy
Contact:

Re: Writing answers instead of choosing menu options

#34 Post by xavimat » Thu Aug 15, 2013 12:03 pm

jw2pfd wrote:I was toying around with your code and I had a suggestion for a potential improvement. It really is just preference as all it does is increase what I consider to be user-friendliness. Instead of having the user entering a list on the front end of the call for answers, you could allow the user to enter it into a string format with answers separated by commas to be parsed/split on the back end.
Thanks, jw2pfd. Yes, it's more user-friendly. I'll add also, before "ans = answers.split(',')" a way to delete possible spaces. Maybe: ans = answers.replace(' ', '')? (I think your code doesn't work if the user writes "park, beach, home" with spaces).
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Writing answers instead of choosing menu options

#35 Post by jw2pfd » Thu Aug 15, 2013 1:41 pm

xavimat wrote:Thanks, jw2pfd. Yes, it's more user-friendly. I'll add also, before "ans = answers.split(',')" a way to delete possible spaces. Maybe: ans = answers.replace(' ', '')? (I think your code doesn't work if the user writes "park, beach, home" with spaces).
Yeah, it would just be a matter of preference as long the user understands the proper syntax. It should be easy for a user to remember either to always use no spaces such as "park,beach,home"; however, I definitely agree that removing the spaces and then splitting by commas would make it so the user could enter it either way and have it work correctly. Your space removal change makes it so it would properly accept either "park,beach,home" or "park, beach, home" which makes it even more user-friendly!

User avatar
TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Writing answers instead of choosing menu options

#36 Post by TrickWithAKnife » Thu Aug 15, 2013 2:11 pm

Realistically, making it user friendly should always be first priority, otherwise there's no point.

Look at it from the user's perspective. I'd like to be able to type "Well... I think I'd prefer the park" and the game would understand it well enough to respond appropriately.

Devs must adapt their content to the audience. It's not the audience's responsibility.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Writing answers instead of choosing menu options

#37 Post by jw2pfd » Thu Aug 15, 2013 2:35 pm

TrickWithAKnife wrote:Realistically, making it user friendly should always be first priority, otherwise there's no point.

Look at it from the user's perspective. I'd like to be able to type "Well... I think I'd prefer the park" and the game would understand it well enough to respond appropriately.

Devs must adapt their content to the audience. It's not the audience's responsibility.
I think I am missing some of the context of your statement. I agree that code should be made as user-friendly and accessible as possible and even more so when the code's purpose is for others to use. Currently, from the player's perspective, xavimat's code does work with the statement "Well... I think I'd prefer the park". The keyword "park" is picked up and then the code can choose what to do for that keyword. Oh well, I may just be misinterpreting your comments.

User avatar
TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Writing answers instead of choosing menu options

#38 Post by TrickWithAKnife » Thu Aug 15, 2013 2:41 pm

More likely, I've misunderstood the conversation between the two of you.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Writing answers instead of choosing menu options

#39 Post by jw2pfd » Thu Aug 15, 2013 2:45 pm

Even more likely, I think we're all on the same page that user-friendliness is awesome.

User avatar
Kokoro Hane
Miko-Class Veteran
Posts: 995
Joined: Thu Oct 27, 2011 6:51 pm
Completed: 30 Kilowatt Hours Left, The Only One Girl { First Quarter }, Crystal Captor: Memory Chronicle Finale, Journey of The Scroll, An Encounter ~In The Rain~
Projects: Gakusei, Final Pirate Haven: Rebellion of Gilfer's Bay, False Hope, The Only One Girl
Organization: Tofu Sheets Visual
Deviantart: kokoro-hane
itch: tofu-sheets-visual
Contact:

Re: Writing answers instead of choosing menu options

#40 Post by Kokoro Hane » Thu Aug 15, 2013 10:31 pm

xavimat wrote:
Kokoro Hane wrote:This code is very useful! I am making a mock-up Internet function in Eileen's (Otome) Love Story, and this code was PERFECT for the "Search" function, that way users can type in keywords. ^.^
Currently, the code only returns the first keyword found. If you need a function able to return more than one keyword, tell me; I can do it.
Yeah, that was a problem, so I had to put somewhere to type as one word. An answer split would make it easier ^.^
PROJECTS:
Journey of The Scroll[COMPLETE][RPG][v.2]
An Encounter ~In The Rain~ [COMPLETE][IntRenAiMo'19]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
The Only One Girl [WiP][Up.5/20/2017][1stQ ver. released]
30 Kilowatt Hours Left [COMPLETE][GameJolt GDC Jam2016]

But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
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: xavimat
Location: Italy
Contact:

Re: Writing answers instead of choosing menu options

#41 Post by xavimat » Fri Aug 16, 2013 6:06 am

@jw2pfd and @TrickWithAKnife: I think the misunderstanding is in the word "user". Me and jw2pfd intended "user" as "the game-developer that uses the reply() code proposed". And TrickWithAKnife meant "the gamer, who plays the game". Nevertheless, I think we all agree in the importance of the user-friendliness.

@Kokoro Hane: I could change the code to return not only a word, but a list. I think I'll have time later today.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
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: xavimat
Location: Italy
Contact:

Re: Writing answers instead of choosing menu options

#42 Post by xavimat » Sat Aug 17, 2013 7:34 am

@ Kokoro Hane: This code returns more than one keywords:

Code: Select all

# Reply2 for Kokoro Hane
# 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 reply2(question = "Yes or no?",
        answers = "yes,no",
        invalid_character = None,
        invalid_answer = "(Invalid answer)",
        show_answers = True):

        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 element == theword and element not in found_it:
                        found_it.append(element)
                        
            if found_it == [  ]:
                renpy.say(invalid_character, invalid_answer)

        return found_it
You call it with "reply2" and the parameters:

Code: Select all

$ r = reply2("Where can we go?", "park, beach, home", e, "Can you repeat, please?")
Note that the list of answers is simpler here, thanks to the suggestion by jw2pfd. You don't need to format the pyhton list ["word1", "word2", "word3"], but only write them inside the quotes: "word1, word2, word3" (with or without spaces, it doesn't matter now).

The variable "r" returns now a list, you can check it this way:

Code: Select all

    if "park" in r:
        e "You have chosen park"
    if "beach" in r:
        e "You have chosen beach"
    if "home" in r:
        e "You have chosen home"

    $ l = len(r)    
    if l > 2:
        e "You have chosen too much."    
Note that we don't use "elif" but separated "if" because all of the can be true. With "len()" you have the total of keywords found in the user's reply.
Last edited by xavimat on Thu Nov 14, 2013 11:04 am, edited 1 time in total.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
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: xavimat
Location: Italy
Contact:

Re: Writing answers instead of choosing menu options

#43 Post by xavimat » Sun Aug 18, 2013 7:29 am

@jw2pfd:
I was intrigued by the "chat" system in fiorica's Doll's Story, but really didn't understand what its purpose is. Does it change some stats according to the phrases written? I played only the female doll branch, not finished, but, anyway, as a player I didn't feel that my sentences did anything.
Can you please explain what your code for Doll's Story tried to do?
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Writing answers instead of choosing menu options

#44 Post by jw2pfd » Sun Aug 18, 2013 9:30 am

xavimat wrote:@jw2pfd:
I was intrigued by the "chat" system in fiorica's Doll's Story, but really didn't understand what its purpose is. Does it change some stats according to the phrases written? I played only the female doll branch, not finished, but, anyway, as a player I didn't feel that my sentences did anything.
Can you please explain what your code for Doll's Story tried to do?
I have many ways that I can approach this conversation, but I am going to mostly stick to how it was coded. The process of coding the input system of "The Dolls' Stories" involved me taking specifications from fioricca and doing my best to implement them. The code started out as simply taking text entry from the user and moving forward to the next line of dialogue if the input matched a set of keywords. The code then became about allowing a little more flexibility for user input. This included having a list of synonyms for each keyword, but the basic principle still applied, "user has to match all keywords". I made a few other changes to the code to provide more tools when checking user input to vary flexibility from prompt to prompt.

The prompts in "The Dolls' Stories" were never really designed to have an effect other than giving the player the feeling that they could speak for themselves to some degree. The complexity of English would make coding something like comprehensive language recognition with accuracy a near impossible task. The goal then is to create the illusion that the user's input has an effect on the game. The key would be in the design of the game and building a system around it. "The Dolls' Stories" was never really designed to have that much complexity. It does raise the question of "why use text entry at all?" and I don't have an answer for that. I do think that text entry is an area that can still be furthered explored in VNs, but the sections of the game that use it would have to be purely designed around it.

I hope my rambling answered your question in some capacity.

User avatar
TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Writing answers instead of choosing menu options

#45 Post by TrickWithAKnife » Sun Aug 18, 2013 9:54 am

I wonder if it would be worthwhile for the people interested in this kind of system - be it practical or academic - working out what they would like to see, and realistic ways to do it. Perhaps more about design rather than actual code, at least initially.

For example, using synonyms as jw2pfd mentioned to increase the chances of recognition, recognising negatives to change the responses, and so on.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

Post Reply

Who is online

Users browsing this forum: No registered users