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
User avatar
Jod
Regular
Posts: 51
Joined: Sat Nov 24, 2012 10:16 am
Projects: F.I.N.
Organization: JodCorp
Location: The Netherlands
Contact:

Re: Writing answers instead of choosing menu options

#16 Post by Jod »

Bit of a chat with Trick on the IRC-channel. Here's the basics on my input system. Some snippets from the code:

Some backgrounds:
-It's a fighting game, multiple inputs are required for one 'fight'. That's the reason I do not allow the same input twice in a row.
-I check for empty input. Since there's a timer going on, empty input is possible. And should also be checked :).

I create a dictionary of allowed input and the results. Also a list of synonyms:

Code: Select all

#FIGHTING DICTIONARY
    #SYNTAX {'fighting_input': [input,'succes?','end of fight?','text','picture','sound','visual effect']
    $ fight_dict = {'fail': ['fail',False,False,'PLACEHOLDER TEXT.','PLACEHOLDER PICTURE', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL'], 
                           'fail_repeat': ['fail_repeat',False,False,'PLACEHOLDER TEXT','PLACEHOLDER PICTURE', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL'], 
                           'fail_empty': ['fail_empty',False,False,'PLACEHOLDER TEXT','PLACEHOLDER PICTURE', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL'], 
                           'punch': ['punch',True,False,'PLACEHOLDER TEXT', 'resources/images/fighting/f_01.png', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL'], 
                           'kick': ['kick',False,False,'PLACEHOLDER TEXT','PLACEHOLDER PICTURE', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL'],
                           'stab': ['stab',True,True,'PLACEHOLDER TEXT','PLACEHOLDER PICTURE', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL'],
                           'snap kick': ['snap kick',True,False,'PLACEHOLDER TEXT','f_02', 'PLACEHOLDER SOUND','PLACEHOLDER VISUAL']} 
    
    $ fight_synonyms = {'punch': ['punch', 'jab', 'hook', 'uppercut'], 'kick': ['kick', 'sidekick', 'roundhouse kick'], 'stab': ['stab', 'shank', 'slash']} 


In the fight I create a list of synonyms input:

Code: Select all

$ possible_inputs = fight_synonyms.keys()
Then I check the input from the player:

Code: Select all

label input_on_list:
        hide countdown
        if player_input == "": #CHECK IF PLAYER ENTERED NOTHING
            $ succes_list  = fight_dict['fail_empty']                
            jump process_fail_result
        elif player_input.lower() == previous_input: #CHECK IF PLAYER ENTERED THE EXACT SAME VALUE AS BEFORE
            $ succes_list = fight_dict['fail_repeat']
            jump check_player_input
        elif player_input.lower() in list_fight_input: #CHECK IF THE PLAYER ENTERED A VALID VALUE FROM THE INPUT LIST
            $ succes_list  = fight_dict[player_input.lower()]
            jump check_player_input
        else:
            $ i  = 0
            while (i < len(possible_inputs)): #CHECK IF THE PLAYER ENTERED A SYNONYM OF A VALUE ON THE INPUT LIST
                $ temp_input = possible_inputs[i]
                $ synonym_list = fight_synonyms[temp_input]
                $ lowered_player_input = player_input.lower() 
                if lowered_player_input in synonym_list:
                    $ succes_list = fight_dict[temp_input]
                    jump check_player_input
                $ i = i + 1
 
            $ succes_list  = fight_dict['fail'] #NONE OF THE ABOVE WAS TRUE, SET VALUES FOR  GENERAL FAIL
            $ previous_input = ""
            jump process_fail_result     
Hope this helps a bit! :)

animedaisuki
Regular
Posts: 129
Joined: Thu Jan 31, 2013 1:07 am
Completed: Zefii Beta 1.0
Projects: Zefii - A Transcendent Journey
Organization: Balibu Studios
Contact:

Re: Writing answers instead of choosing menu options

#17 Post by animedaisuki »

so my game actually has two windows... one for dialogue and one for the chatting system. for the most part, the chatting system is separate from the main game, but it does help to add up affection points and do certain things when certain events occur. what i need to know is:

1) how to make 2 windows
2) where i should code the chatting system: would it go into script, options, screen, or a separate page on its own?

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

#18 Post by TrickWithAKnife »

Put the code wherever you like. Personally I use a new rpy dedicated to chat functionality, just to stay organised.

As for your other question, it's not related to this topic, and you've already made a topic for it.
"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.

animedaisuki
Regular
Posts: 129
Joined: Thu Jan 31, 2013 1:07 am
Completed: Zefii Beta 1.0
Projects: Zefii - A Transcendent Journey
Organization: Balibu Studios
Contact:

Re: Writing answers instead of choosing menu options

#19 Post by animedaisuki »

TrickWithAKnife wrote:Put the code wherever you like. Personally I use a new rpy dedicated to chat functionality, just to stay organised.

As for your other question, it's not related to this topic, and you've already made a topic for it.
sorry, but no one answered... and i couldn't find the post you mentioned last time... i thought it's somehow related because i assume most games are not purely a chatting game (like it's usually part of the game?), so I thought people who are making the chatting system might know

animedaisuki
Regular
Posts: 129
Joined: Thu Jan 31, 2013 1:07 am
Completed: Zefii Beta 1.0
Projects: Zefii - A Transcendent Journey
Organization: Balibu Studios
Contact:

Re: Writing answers instead of choosing menu options

#20 Post by animedaisuki »

hey, just want to thank u for making such a wonderful messaging system! I used it in my game. the test version will be released by the end of this week! I credited you for the messaging system (in the ending song)! Thanks so much again! The game wouldn't have been possible without you!

game website (might change it later on...): http://balibu.weebly.com/index.html
Last edited by animedaisuki on Wed May 22, 2013 4:30 pm, edited 1 time in total.

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Writing answers instead of choosing menu options

#21 Post by Karl_C »

TrickWithAKnife wrote:Do you use IRC? I'd been working on some ideas a few weeks ago (inspired by the same projects), and perhaps some of what I've done could be of use to you.

Some of the features I've got working include:
  • A thesaurus for understanding words with similar meanings.
    "I want to visit the seaside."
  • Being able to process the grammar a little more. For example, being able to recognise negative sentences.
    "I don't feel like going to the beach. Let's go somewhere else."
  • Assigning properties to objects.
    "I can't eat the beach, it's not food!"
What I have is pretty incomplete though, but it does work.
You're possibly looking for this one: GrokItBot: A Python, AIML and Bayesian IM bot

It uses a Bayesian algorithm to provide learning and guessing capabilities:

GrokItBot is intended to cut down on the amount of AIML that needs to be written for very similar inputs. Once you have trained the bot that 'hi', 'lo' and 'yo' all mean the same thing, 'hello', using the Bayesian trainer, then you only need one AIML response. Once trained, it should also be able to guess that 'hi there grokit', 'lo there' and 'yo yo yo yo grandma' all mean the same thing, 'hello'. This cuts down the amount of AIML that needs to be written enormously.
With a Bayesian guessing filter, GrokItBot should take a guess at the topic of conversation and, if it finds no suitable response, ask for clarification.
GrokItBot is *not* intended to be an ALICE bot replacement. I've written GrokItBot to act as a utility rather than a chatterbot.(...)


Even more interesting when it comes to the subject 'Writing answers instead of choosing menu options':

AIML designated callbacks
These are callbacks that can be set within the AIML file allowing you to set conversational triggers that execute your own Python code.


The guy who programmed the bot uses it as an utility and not as an chatbot btw. His intention for programming it was, that he don't have to remember the syntax of each command he's using:

ImageImageImage

BTW: Latest version is on GitHub

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

#22 Post by TrickWithAKnife »

This looks really interesting. I'm looking forward to taking a proper look on Sunday. Hopefully it's not too hard to follow
"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.

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Writing answers instead of choosing menu options

#23 Post by Karl_C »

TrickWithAKnife wrote:This looks really interesting. I'm looking forward to taking a proper look on Sunday. Hopefully it's not too hard to follow
Try the version in GitHub, as it's cleaned of unnecessary IRC/networking stuff.
The developer moved all IRC related code from the other files to 'GrokItBot.py' only too, so I guess it's easier to read.

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

#24 Post by TrickWithAKnife »

Dunno if anyone else had any luck getting it working, but it didn't make much sense to me. Perhaps a rudimentary understanding of Python may have helped.
"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.

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Writing answers instead of choosing menu options

#25 Post by Karl_C »

TrickWithAKnife wrote:Dunno if anyone else had any luck getting it working, but it didn't make much sense to me. Perhaps a rudimentary understanding of Python may have helped.
If you just want to try out, take this one (it's not my code btw.):

Code: Select all

#!/usr/bin/env python

import logging
import webbrowser
import getpass
from AIMLBot import AIMLBot
from optparse import OptionParser
from os import system, getcwd
import sys
import re
import hashlib

if sys.version_info < (3, 0):
    reload(sys)
    sys.setdefaultencoding('utf8')

class ZippyBotCL(object):
  """
  An AIM bot that uses both PyAIML and Reverend Bayes 
  parser to learn and respond to messages.
  
  Duncan Gough 13/03/04
  
  - Updated to switch form TocTalk/AIM to Twisted/IRC
  
  Duncan Gough 11/01/09
  
  PyAIML: http://pyaiml.sourceforge.net/
  Reverend Bayes: http://www.divmod.org/Home/Projects/Reverend/
  Twisted: http://twistedmatrix.com/
  
  GrokItBot: http://www.suttree.com/code/grokitbot/
  """
  def __init__(self, nickname="ZippyBot"):
    super(ZippyBotCL, self).__init__()
    self.nick = nickname
    self.aiml = AIMLBot(self.nick)

  def start(self):
    while 1:
        text = raw_input("> ")
        if text.lower() == "exit":
            sys.exit()
        self.message(text)

  def message(self, msg):
    user = "person"
    if msg.startswith('*** '):
      print msg
      return
    elif self.nick in msg:
      msg = re.compile(self.nick + "[:,]* ?", re.I).sub('', msg)
      prefix = "%s: " % (user.split('!', 1)[0], )
    else:
      prefix = ''

    sentence = self.aiml.on_MSG_IN(user.split('!', 1)[0],msg)
    if sentence.startswith("http"):
        webbrowser.open(sentence)
    print prefix + sentence

if __name__ == "__main__":
  optp = OptionParser()
  optp.add_option('-q', '--quiet', help='set logging to ERROR',
                    action='store_const', dest='loglevel',
                    const=logging.ERROR, default=logging.INFO)
  optp.add_option('-d', '--debug', help='set logging to DEBUG',
                    action='store_const', dest='loglevel',
                    const=logging.DEBUG, default=logging.INFO)
  optp.add_option('-v', '--verbose', help='set logging to COMM',
                    action='store_const', dest='loglevel',
                    const=5, default=logging.INFO)

  opts, args = optp.parse_args()

  logging.basicConfig(level=opts.loglevel,
                      format='%(levelname)-8s %(message)s')
  xmpp = ZippyBotCL()
  xmpp.start()
Source: GitHub: ZippyBot

A hint: In 'learning mode', you have to tell the bot the topic, not just another word with the same meaning (in this case the name of the aiml file where the possible answers are stored). If you 'tell' the bot 'jojojo' and it asks 'What do you mean?', you have to reply 'hello'. Then it will check the contents of 'data/aiml/hello.aiml' the next time.

User avatar
sapiboonggames
Veteran
Posts: 299
Joined: Thu Jan 05, 2012 8:53 am
Completed: I Love You, Brother [BxB]
Contact:

Re: Writing answers instead of choosing menu options

#26 Post by sapiboonggames »

Is there any way to make multiple random warning message?
Like, it can be: "What are you talking about?", "I'm afraid I don't understand that", "Please answer my questions" and the probability of being chosen are random?

And is there anyway to make double keywords? Like, keyword "buy" and "book". So, "buy me a book" equals "go buy a book"

Thanks again for making this, I'm gonna use this
Visit my website: http://www.sapiboong.com

User avatar
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

#27 Post by xavimat »

sapiboonggames wrote:Is there any way to make multiple random warning message?
Like, it can be: "What are you talking about?", "I'm afraid I don't understand that", "Please answer my questions" and the probability of being chosen are random?
I haven't tested this.
In my code (first post), try changing the line:

Code: Select all

invalid_answer = "(Invalid answer)",
with:

Code: Select all

invalid_answer = renpy.random.choice(["What are you talking about?", "I'm afraid I don't understand that.", "Please answer my questions."]),
On the other hand, I'm not sure how to set "double keywords" in my code.
Last edited by xavimat on Sat Aug 03, 2013 10:02 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)

animedaisuki
Regular
Posts: 129
Joined: Thu Jan 31, 2013 1:07 am
Completed: Zefii Beta 1.0
Projects: Zefii - A Transcendent Journey
Organization: Balibu Studios
Contact:

Re: Writing answers instead of choosing menu options

#28 Post by animedaisuki »

I used the original code in my game, and it worked out fine. I still need to expand the database when i release the full version of the game. but the code itself works! For reference, the game is here:
http://lemmasoft.renai.us/forums/viewto ... 11&t=21868

User avatar
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

#29 Post by xavimat »

animedaisuki wrote:I used the original code in my game, and it worked out fine. I still need to expand the database when i release the full version of the game. but the code itself works! For reference, the game is here:
http://lemmasoft.renai.us/forums/viewto ... 11&t=21868
Glad to hear that my code is useful :)
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
Kokoro Hane
Eileen-Class Veteran
Posts: 1237
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

#30 Post by Kokoro Hane »

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"

Post Reply

Who is online

Users browsing this forum: No registered users