The Reliques of Tolti-Aph

An interactive fiction by Graham Nelson (2005) - the Inform 7 source text

Home page

Contents
Previous
Next

Complete text
Section 1(b) - Dice

A die roll is a kind of value. 3d20+9 specifies a die roll[1] with parts dice, sides (without leading zeros), adds (without leading zeros, optional, preamble optional).[2]

To decide which number is roll of (dr - a die roll):
    let the total be the adds part of dr;
    say "[dr]: ";
    repeat with counter running from 1 to the dice part of dr
    begin;
        let the roll be a random number from 1 to the sides part of dr;
        if the counter is not 1, say ",";
        say the roll;
        increase the total by the roll;
    end repeat;
    if the adds part of dr is 0 and the dice part of dr is 1, decide on the total;
    if the adds part of dr is not 0, say "+", adds part of dr;
    say "=", total;
    decide on the total.

Test rolling is an action out of world applying to one die roll. Understand "dice [die roll]" as test rolling. Carry out test rolling: say "For your own amusement, you roll "; let the outcome be the roll of the die roll understood; say ", making [outcome in words]." [3]

Notes

[1]. RPGs are games of chance as well as skill, and the actual rolling of the dice is as much a part of the experience as the randomised outcome. The polyhedral four-, six-, eight-, ten-, twenty- and even hundred-sided dice ubiquitous to RPGs are pleasingly exotic in the hand, but also make possible a wide range of random distributions. W&W uses the traditional notation for such rolls (which evolved as the D&D rules went through successive printings, but became standard around 1980): "3d6+2" means we should roll three six-sided dice, add up the scores showing, then add 2.

[2]. The optional nature of the adds part of a die roll means that "2d4", for instance, is also a legal form. Again, this is a convention imitating the tables which appear in printed RPG rulebooks. What Inform means by the preamble to the adds part is the plus sign: if this had not been specified to be optional, "2d4+" would be legal.

[3]. We added the pointless verb "roll" as a harmless convenience for testing that die rolls work: if the player types "ROLL 3D6+2", the game might reply "For your own amusement, you roll 3d6+2: 2,5,4+2=13, making thirteen."