Writing answers instead of choosing menu options [EDITED]
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.
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.
Re: Writing answers instead of choosing menu options
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.
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.
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Writing answers instead of choosing menu options
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.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. ^.^
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)
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)
Re: Writing answers instead of choosing menu options
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:
Into:
Not much code would have to be changed on the back end. It can be changed to:
Also, additional toying with the code, I removed the recursive call. This has its benefits. The code including the change above is:
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.
Code: Select all
$ r = reply("Where do you want to go?", ["park","beach","home"], e, "Can you repeat your answer, please?")
Code: Select all
$ r = reply("Where do you want to go?", "park,beach,home", e, "Can you repeat your answer, please?")
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
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
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Writing answers instead of choosing menu options
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).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.
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)
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)
Re: Writing answers instead of choosing menu options
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!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).
-
- 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
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.
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.
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.
Re: Writing answers instead of choosing menu options
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.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.
-
- 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
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.
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.
Re: Writing answers instead of choosing menu options
Even more likely, I think we're all on the same page that user-friendliness is awesome.
- Kokoro Hane
- Eileen-Class Veteran
- Posts: 1241
- Joined: Thu Oct 27, 2011 6:51 pm
- Completed: 30 Kilowatt Hours Left, The Only One Girl { First Quarter }, An Encounter ~In The Rain~, A Piece of Sweetness, Since When Did I Have a Combat Butler?!, Piece by Piece, +many more
- Projects: Fateful Encounter, Operation: Magic Hero
- Organization: Tofu Sheets Visual
- Deviantart: kokoro-hane
- itch: tofu-sheets-visual
- Contact:
Re: Writing answers instead of choosing menu options
Yeah, that was a problem, so I had to put somewhere to type as one word. An answer split would make it easier ^.^xavimat wrote: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.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. ^.^
PROJECTS:
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Writing answers instead of choosing menu options
@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.
@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!
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)
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)
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Writing answers instead of choosing menu options
@ Kokoro Hane: This code returns more than one keywords:
You call it with "reply2" and the parameters:
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: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.
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
Code: Select all
$ r = reply2("Where can we go?", "park, beach, home", e, "Can you repeat, please?")
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."
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!
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)
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)
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Writing answers instead of choosing menu options
@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 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!
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)
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)
Re: Writing answers instead of choosing menu options
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.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?
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.
-
- 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
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.
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.
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.
Who is online
Users browsing this forum: No registered users