On Jul 19, 1:21 pm, "scott_mckay" <.> wrote:
> I tried this:
> Before doing anything other than looking or taking the laptop in the Cabin:
> if the laptop is in the Cabin, say "The laptop is still sitting here."
> I know why this doesn't compile based on what Inform me. But then what's the
> best way to do this? It seems impractical to create multiple rules just to
> produce the exact same text. This is a simple case where I'd only have two
> rules so no big deal but I'm thinking ahead here I can imagine many
> scenarios like this where my use of rules would increase quite a bit. I'm
> guessing the answer here is going to be to create a phrase (like "To say
> ...") but that also seems a bit impractical, leading to lots of phrases that
> might differ only in slight details but, in other cases, differ quite a bit.
> Is there some _concise_ section of the manual that tells you how and when to
> modularize or generalize things?
There isn't a simple answer to that question, though! (For this
language or for any other I've used.)
I mean, as a general rule, "don't duplicate code" is sensible. Beyond
that, I would add: organize the code in the way which makes it easiest
for you to conceptualize. (This will vary per author.) But it seems
that you already have this instinct.
That handles "when".
The "how" is going to depend quite a bit on what it is you're trying
to generalize, though. Some tips that sound relevant to what you're
doing:
-- If you're likely to be writing a lot of rules about the same set of
acts, try making those actions into a kind. See 7.15, "Kinds of
action". Once you've defined a kind of action, you can use that as
shorthand in future rules.
-- If you're going to be writing prose that is going to vary based on
a single input (e.g., an object that an action is applied to),
consider using a text property for the object that contains the
relevant information, as in
A thing has some text called the burning description.
The burning description of a thing is usually "[The item described]
goes up in smoke!"
Report burning something:
say "You strike a match and hold it to [the noun]. [burning
description of the noun][paragraph break]".
-- If you're going to be writing prose that is going to vary based on
multiple factors (e.g., the object the action is applied to BUT ALSO
the scene when it is occurring), you may want to consider an activity
instead. Activities are a little more complex to set up, but they
offer the freedom of a whole rulebook in which to express the details
of what you want to write. So for instance
Describing ignition of something is an activity.
Rule for describing ignition of something (called the burning item):
say "[The burning item] goes up in smoke!"
Rule for describing ignition of something (called the burning item)
when the strong wind is blowing:
say "[The burning item] sends up a great deal of smoke, which is
carried off by the wind."
Report burning something:
carry out the describing ignition activity with the noun.