Skip to content
selfsame edited this page Dec 6, 2014 · 3 revisions

Dialogue classes are state machines that intercept input from the client connection.

from dialogue import *

class MyDialogue(Dialogue):
  def initial(self):
    #this message will be sent to client when client.add_dialogue(instance) is called
    return "Enter a fruit(apple, orange, bananna):

  def start(self, s):
    if s in ["bananna", "orange"]:
      self.fruit = s
      self.con.sendLine("good choice!")
      #you can exit the dialogue by returning False
      return False
    if s == "apple":
      #the dialogue can change it's state
      self.state = self.applemode
      return "green or red apple?"
    return "that was not a fruit, try again:"
    
  def applemode(self, s):
    #self.done is an alternate way to end if you want to return a message instead of False
    self.done = True
    return "You like "+s" apples"

Dialogues can be activated by a method on the client connection instance

  #the dialogue can be activated by a method on the client connection instance
  con.add_dialogue(MyDialogue(con))

Dialogues can instantiate other dialogues via their self.con pointer!

Clone this wiki locally