Skip to content

A simple text generator that combines user input variables with simple conditional logic and random heuristics to produce a different story every time it is run.

License

Notifications You must be signed in to change notification settings

Thurinum/story-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Story Generator Demo

A demo for a simple text generator that combines user input variables with simple heuristics to produce a different story every time it is run. Play with it here.

Screenshot 2022-08-10 084245

About this project

This little tool, similar to others found online, allows its user to "fill in the blanks" and generate a custom story based on this input. Besides user-input variables, it makes use of basic conditional logic and simple RNDs to achieve a different narrative every time. The provided demo scenario, however, is very basic, and will need to be rewritten to better demonstrate such capabilities. The story can be viewed in a very ugly virtual book or downloaded as .txt.

This is a completed version of an old project I began years ago, when I was barely proficient in JavaScript. It has been hastily refactored and patched so that it may function as it was originally designed, but no more. Here be dragons! The ability to load scenarios from disk is missing and will eventually be added.

How it works

  1. The story's scenario is loaded from an XML file.
  2. The user input form is populated based on the scenario's variables.
  3. The user fills in the form to its liking.
    • text, time, and select inputs are available
    • some text inputs have a gender as well
  4. The form is parsed and variables' values are stored in an stupid way.
  5. The story is generated by following the scenario's plotline:
    • expanding variables and their pronouns if applicable
    • evaluating conditions on and between some variables
    • picking branches of the plot randomly to select the outcomes
    • choosing words randomly from wordbanks to introduce variety
  6. Voilà.

Anatomy of the scenario file

Scenarios are stored in XML files. A DTD is provided for syntax-checking.

There are 5 main sections in a scenario:

  • variables: Contains the definition of a variable. Used for generating user inputs at runtime.
  • plotline: Contains the actual story and its logic.
  • wordbanks: Contains sets of related words that can be chosed from randomly to introduce variety.
  • praises: Contains random cover praises for the story.
  • reviews: Contains fake reviews of the generated story.

Variables

There are 4 types of variables:

  • text: Will spawn a text input. Has a placeholder and contains a description. Can be gendered.
  • time: Will spawn a time input. Has a placeholder and contains a description.
  • select: Will spawn a select control. Has a placeholder which is actually a description and contains options.
  • internal: Will spawn a hidden control. Cannot be interacted with, but is useful for setting counters to be manipulated throughout the scenario.

Plotline

The plotline has three main content elements that define how its content is parsed.

  • static: Everything inside is parsed. Can contain mostly everything.
  • dynamic: One of its direct children (usually a ) is randomly picked. Allows branching the story randomly.
  • condition: Behaves like a , but is only parsed when its condition evaluates to true.
    • Conditions can be evaluated against values or another variables, using basic arithmetic/string operators (with type coercion).

Besides those flow-controlling elements, other inline tags are used to create content at runtime.

  • var: Expands one of the variables declared in the variables section into its user-input value.
  • pron: Expands into a pronoun that matches a specified variable's user-input gender.
  • randnum: Generates a random number between bounds.
  • randstr: Picks a random string from a specified wordbank.

The values of variables can also be modified as the story goes:

  • set: Assigns a value to a variable. Works for strings and numbers.
  • offset: Increments or decrements a variable. Works for numbers.

Why would you read through this? Still, thanks. Have a great day!
Refer to the demo scenario and the DTD for the explicit syntax rules.

About

A simple text generator that combines user input variables with simple conditional logic and random heuristics to produce a different story every time it is run.

Topics

Resources

License

Stars

Watchers

Forks