In Part 1 I introduced the Inform 7 programming language, reviewed Chris’ opinions why earlier versions weren’t suited for interactive storyworld development, and briefly talked about the inclusion of real numbers in the latest release.

In this installment I’ll go into a little more detail about using real numbers and creating equations in Inform 7. But first a question – Why are real numbers and equations so important in storyworlds?

At their heart, storyworlds are simulations that model dramatic situations using real numbers assigned to character Attributes (real numbers are used because of the fidelity they provide). Frequently, two or more attributes are used in an equation to determine a character’s reaction to a situation and, in order to make these calculation come out correctly, a certain subset of real numbers, called BNumbers, must be used.

That’s why the inclusion of real numbers in this latest version of Inform 7 is such a necessity. Without real numbers it’s impossible to use numbers like 0.75, -0.9884, or 0.97368 in calculations. Without equations it’s impossible to model character behavior.

A BNumber, or bounded number, has a legal range of -1.0 to 1.0 (in practice it never actually hits these maximum values) and it allows internal calculations with multiple attributes to be performed without overflow.

Sometimes, as part of a BNumber calculation, it’s necessary to transform an unbounded number into its bounded equivalent so it can be used in the calculation. Here’s the method to do that transformation.

double TransformToBoundedNumber(double number) { if number > 0.0 x = 1.0 - (1.0 / (1.0 + number)); else x = 1.0 / (1.0 - number) - 1.0); return x; }

Pretty simple as methods go. On this chart you can see how when TransformToBoundedNumber is called with values from -100 to 100 the resulting BNumber is between -1 and 1.

Here’s a Inform 7 experiment that transforms a random unbounded number into a BNumber. Typed user input in the text below is prefixed with the greater than (>) sign.

Equations An Interactive Fiction by Pham Nuwen Release 1 / Serial number 140615 / Inform 7 build 6L02 (I6/v6.33 lib 6/12N) SD Classroom A large blackboard covers one entire wall. >EXAMINE BLACKBOARD There's some computer code written in chalk on blackboard. >EXAMINE COMPUTER CODE The code written on the blackboard is a method to transform a Number into a BNumber. It's written like this: double TransformToBoundedNumber(double number) { if number > 0.0 x = 1 - (1 / (1 + number)); else x = 1 / (1 - number) - 1); return x; } Type "transform code" to run the method with a random number between -100 and 100. >TRANSFORM CODE Transforming 3 into a Bounded Number gives you 0.75 >TRANSFORM CODE Transforming -84 into a Bounded Number gives you -0.98824 >TRANSFORM CODE Transforming 37 into a Bounded Number gives you 0.97368 >transform code Transforming 75 into a Bounded Number gives you 0.98684 >

Here’s the Inform 7 source code for the above experiment.

"Equations" by Pham Nuwen The Classroom is a room. "A large blackboard covers one entire wall." The blackboard is scenery in the Classroom. "There's some computer code written in chalk on blackboard." The computer code is on the blackboard. The computer code is scenery. "The code written on the blackboard is a method to transform a Number into a BNumber. It's written like this:[line break][line break]double TransformToBoundedNumber(double number) {[line break][line break] if number > 0.0[line break] x = 1 - (1 / (1 + number));[line break] else[line break] x = 1 / (1 - number) - 1);[line break][line break] return x;[line break]}[line break][line break]Type 'transform code' to run the method with a random number between -100 and 100." Transforming is an action applying to one visible thing. Understand "transform [something]" as transforming. Instead of transforming the code, try transforming the blackboard. Instead of transforming the blackboard: let unbounded be a random number from -100 to 100; let bounded be a real number; if unbounded is greater than 0: let bounded be 1.0 - (1.0 / (1.0 + unbounded)); say "Transforming [unbounded] into a Bounded Number gives you [bounded]"; if unbounded is less than 0: let bounded be (1.0 / (1.0 - unbounded)) - 1.0; say "Transforming [unbounded] into a Bounded Number gives you [bounded]";

These fifteen lines of code took me maybe eight to twelve hours total to write and debug (I’ve only dabbled in Inform 7 before this). Most of that time was spent figuring out how to shoehorn the seven lines of original code into the Inform 7 syntax.

Based on this experience I do believe that it would be possible to implement a calculation-centric, process-intensive storyworld along the lines that Chris outlines in his books using Inform 7 but I don’t think it would be easy (or pretty). Yes, Inform 7 is a programming language but it’s designed for displaying and parsing text with roots in the text adventures of the 1980’s. While Numbers and equations are supported, they’re just a small part of that world and, in my opinion, they have to be shoehorned into the existing interactive fiction paradigm.

Don’t get me wrong, I’m not trying to dissuade anyone from trying to use Inform 7 to construct storyworlds. My experience with Inform 7 is limited and my experiment was small. The question “Is Inform 7 a good tool for interactive storytelling?” is still debatable. Additional experiments by more knowledgeable practitioners is needed before the book on Inform 7 and interactive storytelling is closed.

In Part 3 I’ll wrap up this series on Inform 7, taking a brief look at Chris’ last two objections to this development tool and its storyworld authoring suitability.