Rollem XML Document Tutorial

Rollem tables consist of a Master Table and zero or more sub-tables.

The minimal Rollem table is nothing more than an opening and closing master tag:


<master>
</master>

Of course, any useful Rollem Master Table will contain at least one table. Tables have a mandatory name attribute. Attributes are currently case sensitive.

<master>

<table name="Hello">
</table>
</master>

That's still not useful yet, since it lacks any entries. Here's the Rollem "Hello World":

<master>

<table name="Test">
<entry> Hello World!</entry>
</table>
</master>

If you run the above file (available as hello.xml), you get the following output:

Rolling...
Hello World!

OK. Not very impressive yet. In order to really do anything with Rollem, you need another two tags: <roll/> and <range/>.

<roll/> is an empty tag, and has one mandatory attribute called expr and one optional attribute called type, which will be explained later (as in a future release. For now, an examination of the included thein.xml will show one of its uses). expr contains an expression that evaluates to a value--typically a die-roll expression such as "1d6".

<range/> is also an empty tag, and has one mandatory attribute called low and one optional attribute called high. low is an integer, which indicates the lowest die-roll for the entry. high, if present, is the highest die-roll for that entry, and must be greater than or equal to low.

Putting this all together, we have the simplest real Rollem table:

<master>

<table name="Hello">
<roll expr="1d2"/>
<entry><range low="1"/> Hello World!</entry>
<entry><range low="2"/> Good-bye, Cruel World!</entry>
</table>
</master>

The above table (available as hello2.xml) produces the following sample output when run through rolltext.py with the -n6 option:

Rolling...
Hello World!
Hello World!
Good-bye, Cruel World!
Hello World!
Good-bye, Cruel World!
Hello World!

Of course, your mileage will vary depending upon the actual random numbers rolled

It would be more useful if you weren't limited to a single table, so that an entry in one table could refer to an entry in another table. To do this, we have the tag <rollon> which takes the mandatory attribute table, and an optional (and currently unimplemented) attribute times. Let's consider one of the included sample tables, the bars.xml table:

<master>
<table name="Bar_Names">
<roll expr="1d7"/>
<entry><range low="1"/><rollon table="Name"/>'s Corner</entry>
<entry><range low="2"/><rollon table="Name"/>'s Shack. Ladies served fresh clams daily.</entry>
<entry><range low="3"/><rollon table="Name"/>'s Bar</entry>
<entry><range low="4"/><rollon table="Name"/>'s Bar & Grill</entry>
<entry><range low="5"/><rollon table="Name"/>'s Tavern</entry>
<entry><range low="6"/><rollon table="Name"/>'s Emporium</entry>
<entry><range low="7"/><rollon table="Name"/>'s Inn</entry>
</table>
<table name="Name">
<roll expr="1d12"/>
<entry><range low="1"/>Ed</entry>
<entry><range low="2"/>Jack</entry>
<entry><range low="3"/>Bob</entry>
<entry><range low="4"/>Mary-sue</entry>
<entry><range low="5"/>Terry</entry>
<entry><range low="6"/>Moe</entry>
<entry><range low="7"/>Larry</entry>
<entry><range low="8"/>Callahan</entry>
<entry><range low="9"/>Delia</entry>
<entry><range low="10"/>Mom</entry>
<entry><range low="11"/>Doc</entry>
<entry><range low="12"/><rollon table="Name"/> and <rollon table="Name"/></entry>
</table>
</master>

Here we see two tables, Bar_Names and Names. Because Bar_Names occurs as the first file in the Master File, Rollem will default to rolling on it (currently there is no way of overriding that default, but there will be in future releases). Rollem will roll a single seven-sided die (written 1d7, as it would be in most published RPGs) to produce an entry in Bar_Names. If that entry in turn contains a rollon tag (and they all do--in fact the entry with range 7 has two of 'em), Rollem will execute that tag as part of producing the value of that entry. This will in turn cause Rollem to roll at least once on the table Name.

Typical output of rolltext.py -n4 bars.xml is:

Rolling...
Larry's Tavern
Callahan's Inn
Terry's Bar
Terry's Emporium

Note that each roll is independent--there's no guarantee (at present) that you won't get duplicate entries (the name Terry came up twice, although as part of two different Bar_Name entries). Note further that whitespace, or lack of it, is preserved (because the apostrophe s occured right after the > of the rollon, the names appeared correctly with 's after them, instead of, e.g. Terry 's Bar.

Finally (for now), if you want to insert a number into the text of an entry, you can use the <eval/> tag, instead of a subtable. <eval> has one mandatory attribute, expr, which is just like expr in the <roll> tag, and again is typically used for die-rolls. (In future releases it will be quite a bit more powerful, allowing you to evaluate variable names and even nearly arbitrary python expressions, but for now die rolls are pretty much it.)

For instance, the following entry (not part of a larger table in this example):

<entry><range low="1"/>There are <eval expr="2d10"/> orcs. The orcs have <eval expr="1d2"> gold-pieces each.</entry>

The above does exactly what you think it would: whenever a 1 comes up on the table, it produces something like:

There are 17 orcs. The orcs have 1 gold pieces each.

Future releases will let you mark up the text so that plurals (1 gold piece, not 1 gold pieces) will be handled correctly. (This already works in the Perl Generate program; I just need to decide how best to mark up the text without making it too ugly.)

To summarize, the currently implemented tags and attributes are:

Actually, there are a few more than that (chance, otherwise, morethan, and reroll), but I wouldn't recommend using them just yet.


Up ArrowTable of Contents Document ReferenceNext Arrow


Joshua Macy
Last modified: Tue Sep 26 15:15:48 -0400 2000