Once a random word, always a random word

This was a new one on me. Even after you assign the result of a say-phrase with at random to a temporary or global variable… saying your newly assigned variable gets another random word from the say phrase.

To say rnd-word:
  say "[one of]1[or]12[or]123[or]1234[or]12345[or]123456[or]1234567[or]12345678[or]123456789[at random]".

zurn is initially "".

When play begins:
  let t be a text;
  repeat with i running from 1 to 3 begin;
    now t is "[rnd-word]";
    say "[t] [t].";
  end repeat;
  say "--.";
  repeat with i running from 1 to 3 begin;
    now zurn is "[rnd-word]";
    say "[zurn] [zurn].";
  end repeat;

produced, e.g.,

1 1234567.
123456789 12.
12345 12.
1234567 1234.
12345 1234567.
12345678 1234.
1 Like

It’s pretty subtle, but it’s documented in WI 20.7, “Making new text with text substitutions.” Basically, Inform stores the intermediate form, the instructions for generating the text as opposed to the text that’s generated, for as long as possible. This is (usually) either until the text is directly printed to the screen, or you explicitly tell the VM to actually generate the text instead of storing the instructions for generating it.

I haven’t actually tried this in the compiler, but you should be able to assign an actual string of characters in t or zurn by changing (e.g.) now t is "[rnd-word]" to now t is the substituted form of "[rnd-word]".

1 Like

Thanks. I had wondered if it was related to this issue but it turns out it’s the exact same thing.

1 Like

Yeah, I’ve been playing with using this “feature” along with “the substituted form of”. It’s kind of a neat thing. For cases where you simply want a randomized word or phrase used multiple places and contexts, this can make your code that much more succinct.

1 Like