"The Roller" A JavaScript generator template ----------------------------------------------------------------------------------------------- For a start, have a closer look at the simple "Public servant generator", placed at http://generating.strolen.com/gen/bureaucracy.html You can ignore all the funky things around, JavaScript code, formatting tags and so on. Concentrate on the part marked DATA STORAGE AREA - this is where the meat is placed. What you see, are the two function calls that can make the trick. Separated into a few paragraphs (tables), there is always a single "makeTable" command, followed by several "add" commands. Read a table or two to see what they do, then glance through all of them. If you haven't already, generate a few results to see how it works on the outside. Simply, a result from each table is generated, put together with others with flavour text, creating sentences of random contents, but (hopefully) making enough sense for the user. Syntax: The makeTable command has at least two parameters. One is the table's name, that should be kept short, and unique. The other is the initial string, that will be attached to every generated result. The third, optional parameter may be CHECK, if set the table will be always used during a run. makeTable("Table 1B","he"); - this table is called "Table 1B", and prefixes all results with a "he". makeTable("Table A","The public servant",CHECK); - Table A attaches to all of its results the string "The public servant". The CHECK parameter ensures, that this table will be always used during the run of the program, and will always generate some result. makeTable is, logically, a command that creates a table, the add commands that follow make out its contents. The add command has at least one parameter - it is the actual entry in a table. An optional parameter can be the name of another table, in effect a link to it. If such an item is generated, the script will make use of that linked table, too. Let's say a table looks like this: makeTable("Table A","The public servant",CHECK); add("is cheerful."); add("is in a good mood."); ... add("is an annoyance:","Table 1B"); As CHECK is set, This table will be always generated from. There are now three plus possible results, each can be generated with the same probability, each will be prefixed with the same string - "The public servant is cheerful.", "The public servant is in a good mood.", and so on. The final result leads to another table, so when it is generated, the Table 1B is used as well, producing the result - "The public servant is an annoyance: ", plus whatever is generated there. And this is how the script works. It goes through all the tables that have the CHECK set (sequentially, in the order they were written), and randomly picks from whatever is inside. Should any generated result contain a link to another table (preferably one that doesn't have a CHECK), the script will go deeper, and generate another result from this deeper table. You can create an entire network of tables, and sub-tables, that can create complicated results, based on what they generate. ----------------------------------------------------------------------------------------------- This amazing technology has been developed by me, the person known as manfred on the Strolen's Citadel, otherwise as Peter Sidor. It works well for me, but it of course doesn't have to work for you - shortly, I offer you no guarantee whatsoever, along with my hopes that you will have as much fun with it as I had.