Text Variations

version 4 by Jon Ingold

  • Home page
  • Beginning
  • Next

  • Documentation

    Firstly, credit where credit is due: the underlying I6 code here was posted to rec.arts.int-fiction by Andrew Plotkin. The Glulx variants use code from Roger Firth's JustEnoughGlulx.h. These parts are the magic stuff; what's on top is purely whistles and bells.

    Text Variations allows varying output to be placed directly into a say line. Explanation is easiest by example:

        say "You flip the coin. [one of]Heads[or]Tails[purely at random]."
        say "[one of]The phone rings[or]The phone rings a second time[or]The phone rings again[stopping]."
        say "You turn the light switch [one of]off[or]on[cycling]. Nothing happens."
        say "The newspaper headline is: [one of]War Casualties[or]Terrorists[or]Banks[sticky random] [one of]Continue To Expand[or]Lose Out[sticky random]."
        say "The light changes randomly again; now it's [one of]green[or]amber[or]red[at random]."

    Note the last two examples are not random: "sticky random" will make a random choice on first printing and stick to it, and "at random" will each time choose any entry except the last one printed.

    You should be aware that the history of a say statement is kept track of based on the text within it, so an "off[or]on" somewhere will conflict with an "off[or]on" somewhere else. This has disadvantages (the light switch example above would be no good as part of a kind description, for instance). There are some advantages too:

        say "'Sorry, mate, this is the train from [one of]Edgware[or]Paddington[or]Baker Street[at random] to [one of]Edgware[or]Paddington[or]Baker Street[at random].'"

    ...will never say "the train from Edgware to Edgware".

    However, should you need to distinguish between identical say phrases, use the [tip buffer <n>] substitution. This causes the number n to be added into the "score" of the text substitution; so by putting different tip numbers into different say phrases they will be considered to be different.

    Finally: you can get at information of what's been printed using two phrases. The most useful is

        the index of the last buffer

    which will return the index score of whatever the last substitution was. This will be a number corresponding to which choice was printed last, from 1 to n, except if the choice was "purely at random", in which case it will always return zero. So for example:

        say "A [one of]black cab[or]bus[at random] pulls up at the kerb.";
        if the index of the last buffer is 1, move the taxi to the location; otherwise move the bus to the location.

    If you need to dig up the result of a old substitution (say to read off the state of a light bulb, though this is a terrible way to solve that kind of problem), you can achieve this by reprinting the options phrase exactly (including tip buffers as required) but leaving off the last bracket; and then referring to "the index of the buffer". Note this will not cause any text to be printed. So for example:
        say "You reach for the shelf";
        say "[one of]off[or]on";
        if the index of the buffer is 1, say " but it's too dark to see!" instead;
        say ", plainly lit by the bulb in the centre of the room.".

    Note, you shouldn't use "the index of the last buffer" here, as it won't finish off the substitution line correctly.

    Finally, the Glulx code provides two useful functions in I6: Stream_To_Array(array_name) and _Unstream. These perform equivalent functions to I6's @output_stream 3 array_name and @output_stream -3.