[Tutor] Hands-on beginner's project?

Lie Ryan lie.1296 at gmail.com
Wed Jun 25 18:43:47 CEST 2008


If it was me, I'd elaborate it a bit more by separating between program
(logic) and story (data). This would make it possible to tell story
without touching the program's code.

like this (in pseudocode):

# main.py

def querier(query):
    while True:
        print query.prompt
        t = raw_input()
        if t in query.ans:
            return query.ans[t]
        else:
            print 'Unrecognized prompt'

def tell(storyfile):
    """ Tell a story and process response """
    # read from the storyfile, the <story> node
    print storyfile.story

    try:
        if storyfile.end:
            quit()
    except AttributeError:
        pass

    # process the prompts and answers
    if storyfile.query:
        return querier(storyfile.query)

def main():
    while True:
        nextstory = tell(story)
        if nextstory = ending:
            break
        else:
            story = nextstory
        

# chapter1.sto
<story>
  this is an interactive story test
</story>
<query>
  <prompt>You come across a chasm, would you like to jump?</prompt>
  <ans goto="chapter2.sto">y</ans>
  <ans goto="chapter3.sto">n</ans>
</query>

# chapter2.sto
<story>
  You have chosen to leap across the chasm
  Sadly you forgot you are carrying an anvil
  What part of b-bye don't you understand?
<story>
<end type="dead" />

# chapter3.sto
<story>
  You wisely chose to turn back home
  The anvil you are carrying would surely cause you
  to plummet to your death
</story>
<end type="happyending" />



More information about the Tutor mailing list